https://github.com/danielberkompas/async
Async/Await pattern for Elixir
https://github.com/danielberkompas/async
Last synced: over 1 year ago
JSON representation
Async/Await pattern for Elixir
- Host: GitHub
- URL: https://github.com/danielberkompas/async
- Owner: danielberkompas
- License: mit
- Created: 2015-04-07T23:42:23.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-07T23:53:05.000Z (about 11 years ago)
- Last Synced: 2025-01-22T08:38:15.595Z (over 1 year ago)
- Language: Elixir
- Size: 113 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Async
=====
The Async/Await pattern for Elixir! For those who prefer this:
```elixir
def MyModule do
use Async
def my_function do
expensive_result = async OtherModule.expensive_operation(arg1, arg2)
lots_of_counting = async for num <- 1..10_000_000, do: num * 2
# ...
await expensive_result
await lots_of_counting
end
end
```
To this:
```elixir
def MyModule do
import Task, only: [await: 1, async: 3, async: 1]
def my_function do
expensive_result = async OtherModule, :expensive_operation, [arg1, arg2]
lots_of_counting = async fn -> for num <- 1..10_000_000, do: num * 2 end
# ...
await expensive_result
await lots_of_counting
end
end
```
## Should you use this?
No. Probably not. Well, maybe. It's only 20 lines of code, so what could
possibly go wrong?
## Installation
Get it from Github by updating your `deps` function:
```elixir
defp deps do
[{:async, github: "danielberkompas/async"}]
end
```
Then run `mix deps.get` to install.
## License
MIT.