What happens if you don’t await* and async*?
With awaits, if you skip the await, the function still gets queued and called but your function doesn’t get to know the result.
I’m seeing some behavior with await* that if I don’t await* it then the code never actually gets run. Is that the case? I guess I can always not await any actual async termination points in my tree, but I was hoping to get the same behavior.
It’s not necessary to
await* because computations are are simply inert objects, unless you are
await*-ing them. So the only effect they cause is filling up memory with garbage if you don’t really use them. Nothing bad happens. If you know Haskell, this is like gadgets of type
IO String, you can compose them to get bigger, sequential
IO x, but they are just dormant.
Note that this is different from
async, where the message (potentially to self) will be sent. This also justifies the
*: meaning zero or more sends. If you don’t
await* it is definitively zero
@skilesare This info is from async* release notes
async* value has no effect unless
await* of the same
async* value repeats its effects.
@skilesare Do you have a nice example of async* functions (preferably in a module) for documentation purposes in the Motoko Book?
My goals for that chapter of the book (async programming):
I need to clearly state the difference between async and async* and explain to a beginner when messages are sent, when execution is halted, when memory is rolled back (commit points), atomicity, errors, traps, try catch etc.
Any feedback and advice on this (arguably the most important) part of the book, would be much appreciated
Not a lot of good ones yet, but I have been working on a Star.mo module that helps with keeping track of state inside of async* functions: GitHub - icdevs/star.mo: A library for dealing with async* state.