Skip to content

Add support for async tasks #277

@irh

Description

@irh

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions