# Optionally async method in API of a package

**URL:** https://discourse.julialang.org/t/optionally-async-method-in-api-of-a-package/94740
**Category:** New to Julia
**Tags:** api, async
**Created:** [February 16, 2023, 7:52pm UTC](https://discourse.julialang.org/t/optionally-async-method-in-api-of-a-package/94740 "2023-02-16T19:52:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![danlkv](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@danlkv](https://discourse.julialang.org/u/danlkv)
#### Post date: [February 16, 2023, 7:52pm UTC](https://discourse.julialang.org/t/optionally-async-method-in-api-of-a-package/94740/1 "2023-02-16T19:52:16Z")

</div>

I’m developing a package which submits some jobs over the network. My main `do_job(...)` function uses `@async` and sends data over without blocking so I can submit multiple jobs and potentially handle them in parallel. However, having async API as a default might be overly complex. Often users will effectively wrap it with `fetch(do_job(...))`.

I am new to the Julia community and it seems there should be an idiomatic way to have such an API. Here are the options I came up with:

1. keyword parameter: `do_job(...; async=False) = async ? do_job(...) : fetch(do_job(...)) `
2. two functions: `do_job(...)` and `do_job_async(...)`
3. Make `do_job` synchronous and let the user do `@async(do_job(...))` if they need to do jobs in parallel.
4. …Any suggestions?
