You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be good to have async functions in Koto, and I think that it would be a natural extension of the existing Generator concept to add support for async workflows.
Generator functions work by creating an iterator when first called, which contains a VM that's responsible for executing the function, suspending execution each time yield is encountered. Each time .next() is called the iterator runs until the next yield expression, or the function exits.
I think generators could be replaced with a new Task value type that supports an await expression alongside the existing yield.
await would suspend execution of the task while waiting for output from some other task. The task's VM would either block on the awaited result becoming available, or it could be managed by an async runtime that monitors the progress of multiple parallel tasks.
So, the new Task type will be able to:
be suspended while waiting for the output of another task (with await).
yield a series of values (by declaring itself as iterable to the runtime).
be used in a blocking context (like when a generator is wrapped in an iterator).
be used in a non-blocking context (like in an async runtime).
The text was updated successfully, but these errors were encountered:
Some groundwork for this was implemented in #291 - the VM now has an execution_state field which has a Suspended variant, used when a generator has just yielded a value.
Additionally, continue_running now returns a ReturnOrYield enum that lets the caller know the nature of the resulting value.
ReturnOrYield could be extended (and renamed) to include an Await variant that passes the task that's being waited on to an executor (or something 🙃).
It would be good to have async functions in Koto, and I think that it would be a natural extension of the existing Generator concept to add support for async workflows.
Generator functions work by creating an iterator when first called, which contains a VM that's responsible for executing the function, suspending execution each time
yield
is encountered. Each time.next()
is called the iterator runs until the nextyield
expression, or the function exits.I think generators could be replaced with a new
Task
value type that supports anawait
expression alongside the existingyield
.await
would suspend execution of the task while waiting for output from some other task. The task's VM would either block on the awaited result becoming available, or it could be managed by an async runtime that monitors the progress of multiple parallel tasks.So, the new
Task
type will be able to:await
).The text was updated successfully, but these errors were encountered: