Add language extensions for asynchronous functions.
Co-routines are making a comeback in programming languages lately. We probably ought to follow the trend.
Suggestion:
-
Change the behavior of calling a generator function concurrently:
- Register the generator argument and callback.
- Have
yield()
complete with the above value(s) rather than suspending execution.
This solves issues where the generator callback gets called before
yield()
is reached. -
Add a new modifier
__async__
for functions:
__async__ int foo(mixed ...)
{
return 17;
}
Which would be similar to:
Concurrent.Future /*(int)*/ foo(mixed...)
{
Concurrent.Promise __async_promise__ = Concurrent.Promise();
__generator__ foo_generator()
{
__async_promise__->failure(catch {
__async_promise__->success(17);
return UNDEFINED;
});
return UNDEFINED;
}
foo_generator()();
return __async_promise__->future();
}
- Add special form
await(Concurrent.Future f)
:
__async__ int foo(Concurrent.Future f)
{
mixed q = await(f);
}
Which would be similar to:
__async__ int foo(Concurrent.Future f)
{
f->on_await(continue::this_function);
mixed q = yield(UNDEFINED);
}
Where on_await
would be implemented similar to:
this_program on_await(function f)
{
return on_success(f)->on_failure(f, throw);
}
Edited by Henrik (Grubba) Grubbström