Corner.Async (corner v0.1.3)
This Module can be use to define the async function.
A async function return a Promise
.
About the Promise
see more at Corner.Promise
.
use/1
will inject alias Corner.Promise
and
import Promise, only: [await: 1]
, import Corner.Async
.
example
Example
iex> use Corner.Async
iex> fun = async fn a,b -> a + b end
iex> is_function(fun,2)
true
iex> p = fun.(1,2)
iex> is_struct(p, Promise)
true
iex> await p
{:resolved, 3}
Link to this section Summary
Link to this section Functions
async support for fn
.
example
Example
iex> import Corner.Async, only: [async: 1]
iex> f = async fn a, b -> a + b end
iex> p = f.(1,2)
iex> is_struct(p, Corner.Promise)
true
iex> Corner.Promise.await(p)
{:resolved, 3}
async for def
, defp
or defgen
.
About defgen
see Corner.Generater
.
example
Example
iex> defmodule AsyncFunction do
...> import Corner.Async
...> async def sum(a,b) do
...> a + b
...> end
...> end
iex> alias Corner.Promise
iex> v = AsyncFunction.sum(1,2)
iex> is_struct(v, Promise)
true
iex> Promise.await(v)
{:resolved, 3}