Concepts

Controlled asynchronous outcome

Try the free JavaScript compiler

Create a controllable pending operation with the Promise constructor to test explicit sequencing without relying on wall-clock delay.

Formal Syntax & Structure

javascript syntaxjavascript
let release; const promise = new Promise(resolve => { release = resolve; });

Working Example

Example Snippetjavascript
(async () => {const assert=require("node:assert/strict");let release;const p=new Promise(r=>{release=r;});const work=p.then(x=>x*2);release(4);assert.strictEqual(await work,8);console.log("fulfilled",await work);})()
JavaScript Reference