`.and_then()` - dynamic continuations
Implement and_then() which allows a construct like
spawn(a.and_then(b).and_then(c));
This would be syntactic sugar for something like this:
spawn([](){
auto a_result = a();
auto b_result = b(a_result);
c(b_result);
});
This chaining should be applicable dynamically. b must be a function or coroutine function, but a could be any awaitable.
This should be generalizable to coroutines and regular functions. Pass parameters from the output of the first function into the input of the next function.
What requirements are placed on a to support efficient dispatch to b without requiring the introduction of a task wrapper?
How does this behave with awaitable customizations (run_on() / resume_on() / with_priority())? Should it be parsed in a left to right fashion, and each task to the right inherits the behavior of the tasks to the left? Or should the customization be contained to the individual task it was applied to?
The and_then awaitable needs to expose customizations, since customizations can't be applied to its parameter, which is only a function pointer and not a task. It would need to then apply those customizations at runtime to the coroutine created after invoking the function pointer, before dispatching it for execution.