crow/parallel.crow
(source)
await
[t
] t
(a
t
future
)
await-result
[t
] (t
, exception-and-backtrace
) result
(a
t
future
)
yield-fiber
void
()
Just yields the fiber temporarily. It may be restarted immediately.
new
[t
] t
future
(value
t
)
Converts a value to a future resolved with that value.
rejected
[t
] t
future
(err
exception-and-backtrace
)
Future resolved with an exception.
parallel
record
nominal
with-block
[t
] t
future
(anonymous
parallel
, f
shared
t
(void
))
Run f
in a new fiber with a new exclusion and return a future for its result.
new-exclusion
record
nominal
This is like running something with parallel
and then waiting on it.
The purpose is to allow other fibers with the current exclusion to run while waiting.
with-block
[t
] t
(anonymous
new-exclusion
, f
shared
t
(void
))
later
record
nominal
with-block
[t
] t
future
(anonymous
later
, f
mut
t
(void
)) t
shared
shared
Run f
in a new fiber with the current exclusion. So it can't run until the current fiber yields.
forget
[t
] void
(a
t
future
)
Does not await the future, but will log any exceptions from the future once it is done.
fire-and-forget
record
nominal
with-block
void
(anonymous
fire-and-forget
, f
shared
void
(void
))
Runs 'f' in parallel and logs any exceptions, but does not await it.
parallel-collection
[col
] record
collection
col
parallel
[col
] col
parallel-collection
(a
col
)
for-loop
[out-elem
, in-col
, in-elem
] out-elem
array
(a
in-col
parallel-collection
, f
shared
out-elem
(in-elem
)) out-elem
shared
, in-elem
shared
, (in-col
, in-elem
) iterate
, in-col
size
shared
shared
iterate
size
For each element of a
, runs f
in parallel. Then awaits them all.
for-loop
[in-col
, in-elem
] void
(a
in-col
parallel-collection
, f
shared
void
(in-elem
)) (in-col
, in-elem
) iterate
, in-col
size
, in-elem
shared
iterate
size
shared
Same as the above but returning 'void'.
parallel-concat
[col
] record
nominal
collection
col
Runs f
in parallel for each element of a
and concatenates results.
for-loop
[out-elem
, in-col
, in-elem
] out-elem
array
(a
in-col
parallel-concat
, f
shared
out-elem
array
(in-elem
)) out-elem
shared
, in-elem
shared
, (in-col
, in-elem
) iterate
, in-col
size
shared
shared
iterate
size
filter
[out-col
, in-col
, elem
, builder
] out-col
(a
in-col
parallel-collection
, f
shared
bool
(elem
)) (in-col
, elem
) iterate
, in-col
size
, (out-col
, elem
, builder
) build
, elem
shared
iterate
size
build
shared
Runs f
in parallel for each element of a
and returns results for which it was true
.
chunked-parallel
[col
] record
nominal
collection
col
chunk-size
nat64
Works like parallel
, but works in groups of 'chunk-size' elements to reduce parallelism.
chunkable
[col
, iter
, elem
] spec
col
shared
, elem
shared
, (col
, iter
) groupable
, (col
, elem
) iterate
shared
shared
groupable
iterate
for-loop
[out-elem
, in-col
, in-iter
, in-elem
] out-elem
array
(a
in-col
chunked-parallel
, f
shared
out-elem
(in-elem
)) out-elem
shared
, (in-col
, in-iter
, in-elem
) chunkable
shared
chunkable
for-loop
[in-col
, in-iter
, in-elem
] void
(a
in-col
chunked-parallel
, f
shared
void
(in-elem
)) (in-col
, in-iter
, in-elem
) chunkable
chunkable
filter
[out-col
, in-col
, in-iter
, elem
, builder
] out-col
(a
in-col
chunked-parallel
, f
shared
bool
(elem
)) out-col
shared
, (in-col
, in-iter
, elem
) chunkable
, (out-col
, elem
, builder
) build
shared
chunkable
build
future
[t
] builtin
In a JS build, this is a 'Promise'.