FutoIn AsyncSteps
raw JSON →FutoIn AsyncSteps mimics traditional threads of execution in a single-threaded event loop, supporting cancellation, exit handlers, thread-local storage, and synchronization primitives like mutexes and throttles. Current stable version is 2.5.6, released under a stable maturity (status 3). It builds on the FTN12: FutoIn Async API v1.13 specification. Key differentiators include explicit step-based control flow (add, parallel, error handling) rather than Promises or async/await, though it integrates with Promises via as.await(). It is designed for both Node.js (>=8) and browser environments, providing ES5 CJS modules under es5/ and pre-built webpack dists under dist/. Synchronization primitives like Mutex are available for coordinated concurrent execution.
Common errors
error TypeError: $as is not a function ↓
import $as from 'futoin-asyncsteps' or const $as = require('futoin-asyncsteps'). error Cannot find module 'futoin-asyncsteps' ↓
npm install futoin-asyncsteps and ensure import path is correct. error as.success is not a function ↓
Warnings
gotcha Calling as.success() more than once or after as.error() in a step causes undefined behavior. ↓
gotcha Synchronization primitives (Mutex, Throttle) require WeakMap polyfill in older browsers. ↓
gotcha The as.state object is shared among all steps in the same AsyncSteps instance; mutations persist across steps. ↓
gotcha Using as.await() with a rejected Promise will trigger error handling in the AsyncSteps flow, not throw an unhandled rejection. ↓
gotcha Parallel step results are not automatically merged; you must store results in as.state manually inside each parallel branch. ↓
Install
npm install futoin-asyncsteps yarn add futoin-asyncsteps pnpm add futoin-asyncsteps Imports
- $as wrong
const $as = require('futoin-asyncsteps').defaultcorrectimport $as from 'futoin-asyncsteps' - AsyncSteps wrong
import AsyncSteps from 'futoin-asyncsteps'correctimport { AsyncSteps } from 'futoin-asyncsteps' - Mutex wrong
const Mutex = require('futoin-asyncsteps').Mutexcorrectimport { Mutex } from 'futoin-asyncsteps' - $as (browser) wrong
import $as from 'futoin-asyncsteps' in non-module scriptcorrect<script src='dist/futoin-asyncsteps.min.js'></script>... $as(...)
Quickstart
const $as = require('futoin-asyncsteps');
const root = $as();
root.add((as) => {
console.log('Step 1');
as.success('done');
}).add((as, result) => {
console.log('Step 2 received:', result);
as.success();
});
root.execute();