aboutsummaryrefslogtreecommitdiff
path: root/std/async.pk
blob: 87b1abc61e5c97344a81603aa15a6e28648e4af9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## std.async: Zig-style colourless async/await.
## Future types, the async macro, and the await function.
# reference: https://kristoff.it/blog/zig-colorblind-async-await/

## A standard Future type. Opaque.
@[opaque]
pub type Future[T] = struct
  ...

## The `async` macro transforms any function call into
## an asynchronous call returning a Future of some type.
##
## This does not "just work". Compiler magic is necessary to package up
## *any* block into something independently callable.
pub macro async[T](call: T): Future[T] =
  ...

## The `await` function blocks on a Future[T] call until it returns a value.
pub func await[T](self: Future[T]): T =
  ...

examples
  std.net.connect()
  print 1.async.await