# `Magpie.Async`
[🔗](https://github.com/alexcassol/magpie/blob/v0.3.1/lib/magpie/async.ex#L1)

Waits for Dropbox asynchronous jobs to complete.

Batch endpoints (`copy_batch`, `move_batch`, `delete_batch`,
`create_folder_batch`, `share_folder`, ...) may return
`%{".tag" => "async_job_id", "async_job_id" => id}` instead of a final
result, expecting you to poll the matching `check` endpoint until the job
leaves the `"in_progress"` state. `await/4` runs that loop with
exponential backoff:

    {:ok, launch} = Magpie.Files.MoveBatch.move_batch(client, entries)
    {:ok, result} = Magpie.Async.await(client, launch, &Magpie.Files.MoveBatch.check/2)

`await/4` also accepts the job id directly, and passes through launches
that completed synchronously (`%{".tag" => "complete"}`), so it can be
piped unconditionally after any batch call.

# `await`

Polls `check_fun` until the job completes, fails, or `:timeout` elapses.

  * `launch_or_id` — the result map of a batch call (`%{".tag" => ...}`)
    or an `async_job_id` string
  * `check_fun` — two-arity function `(client, async_job_id)` hitting the
    job's check endpoint, e.g. `&Magpie.Files.MoveBatch.check/2`
  * `opts`:
    * `:interval` — initial poll interval in ms (default `500`)
    * `:max_interval` — backoff cap in ms (default `5_000`); each poll
      doubles the interval up to this value
    * `:timeout` — overall deadline in ms (default `60_000`)

Returns `{:ok, result}` when the job reports `"complete"`,
`{:error, :timeout}` on deadline, or the job's error/failed response
as-is.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
