AsyncSteps intro
FutoIn AsyncSteps is a concept of asynchronous program flow coding in a way which closely mimics traditional synchronous threads.
The concept is clearly different from trivial Promise, async/await, or generic coroutines, but it matches and exceeds those in speed. In fact, it has a much lower theoretical flow switching overhead than required by bare metal coroutines with full register file dump & restore plus other maintenance work.
The FutoIn AsyncSteps concept was born when none of those were standardized. Also, it is implemented in bare metal languages like C++ and supports an ISO C11 binary interface. It’s the essential part which allows safe transfer of complex financial business logic to a scalable asynchronous runtime.
Overall features & goals:
- Mimic “thread of execution”:
- allow cancelling from outside,
- cancel by timeout as a standard feature,
- “atexit”-like cleanup actions.
- Mimic “try-catch”:
- clear scoping of inner blocks,
- mimic “stack unwinding” on errors and cancels,
- RAII-like cleanup on async stack unwinding,
- support recovery actions in
catch.
- Mimic “worker pool”:
- parallel execution of steps,
- early cancel on error.
- Mimic “thread local storage”:
- per-instance
state, - also shared within worker pool.
- per-instance
- Mimic synchronization primitives:
Mutex- limit number of concurrent “threads” in critical section,Throttle- limit number of critical section entries in period,Limiter- merge ofMutexandThrottle.
- Support loops:
- generic
loopwithcontinueandbreakusing optional labels, repeatfor specified number of times,foreachover arrays, objects, sequences, and iterators.
- generic
- Cross-technology exceptions and error info:
- assumed to be passed over network,
- error code - persistent string code,
- error info - arbitrary human-readable string.
- Integration with any external async wait approach:
- including regular callbacks,
Promise, andawait, - support timeouts & cleanup handlers out-of-the-box.
- including regular callbacks,
- Chain passing of “result->input” sequences:
- explicit
as.success()arguments are passed to the next step.
- explicit
- Integration with implementation-specific Futures and Promises:
- acts as a regular step.
- Memory Pool management for non-GC technologies:
- allows fine control of memory limits per event loop instance,
- removes heap synchronization overhead with around 30% boost in tests.
- Designed for integration into foreign event loops and input/output reactors.
Specification
FTN12: FutoIn Async API is a single AsyncSteps specification.
Reference Implementations
-
C++:
- FutoIn Core C++ API:
- FutoIn Core C++ Reference Implementation with submodules:
- FutoIn Core C++ AsyncSteps Reference Implementation:
-
Java:
- FutoIn Core Java API:
- FutoIn Core Java Reference Implementation:
-
JavaScript:
-
PHP (a decade outdated):