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.
Provide non-blocking IO primitives (e.g. epoll based) and write a standard-library handler for an
asynceffect.This could have operations:
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
epollto 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.