Skip to content

direct-style async IO as an effect #94

@DanGooding

Description

@DanGooding

Provide non-blocking IO primitives (e.g. epoll based) and write a standard-library handler for an async effect.

This could have operations:

// parameter is the return type
type IO<a>
  Read<string>(file, int)
  Write<int>(file, string)

effect async
  ctl await (IO<a>) : a
  ctl await_all (list<IO<a>>) : list<a>
  ctl await_first (list<IO<a>>) : a

The compiler will already handle threading through closures everywhere.

We can write a handler in koka that implements the scheduler. To await an operation it should kickoff that operation, store the resumption accessible by the file descriptor, then use epoll to wait for any of the currently pending operations to have completed. Then it should run the relevant resumption.

This setup allows running raw IO in parallel. It doesn't allow running two asynchronous koka functions in 'parallel'. To do that - install another async handler. This one should keep a queue of all runnable koka functions, and prefer starting any of them to epoll_waiting for IO to complete.

This relies on a ton of features: files, strings, and if we want to implement the scheduler in koka: mutable state, GADTs, queues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions