AsyncSteps intro

FutoIn AsyncSteps is 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 those in speed. By fact, it has much lower theoretical flow switching overhead than required by bare metal coroutines with full register file dump & restore + other maintenance work to do.

FutoIn AsyncSteps concept was born when neither of those were standardized. Also, it is implemented in bare metal languages like C++. It’s the essential part which allows safe transfer of complex financial business logic to scalable asynchronous runtime.

Overall features & goals:

  • Mimic “thread of execution”:

    • allow cancelling from outside,
    • cancel by timeout as 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.
  • Mimic synchronization primitives:

    • Mutex - limit number concurrent “threads” in critical section,
    • Throttle - limit number of critical section entries in period,
    • Limiter - merge of Mutex and Throttle.
  • Support loops:

    • generic loop with continue and break,
    • repeat for specified number of times,
    • foreach over array or object.
  • Cross-technology exceptions and error info:

    • assumed to be passed over network,
    • error code - persistent string,
    • error info - arbitrary string.
  • Integration with any external async wait approach:

    • including regular callbacks, Promise and await,
    • support timeouts & cleanup handlers out-of-box.
  • Chain passing of “result->input” sequences:

    • explicit as.success() arguments are passed to the next step.
  • 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.


FTN12: FutoIn Async API is a single AsyncSteps specification.

Reference Implementations