Skip to content
On this page

Quantum Promise

It's like a promise, but with more lazy procrastination: it only starts once you await or .then() it.

const qp = require('quantum-promise'); //

async function dowork() {
	await q.delay(1000);

const promise = qp(dowork);
console.log("about to run");
await promise;

Is used as a mix-in

An object can become an awaitable deferred action by using this as a mix-in, and can replace the run() behavior after creation but before awaiting:

class Foo {
	constructor() {
		Object.assign(this, qp(this.doDefault));

	doDefault() {
		console.log("default action that's triggered by await");

	configEdgeCase() {
		this[] = () => {
			console.log("running edge case");

const foo = new Foo();
await foo;

All this weirdness allows squirrelnado to express ETL jobs with the following await => commence syntax, because I dislike verbose boilerplate:

const {read} = require('@ashnazg/squirrelnado');
const rows = await read('db://endpoint/tablefoo'); // the lack of any explicit termination means "resolve to array of rows"

// or instead of calling await on the opening step, chain them and await the last:
await read('db://endpoint/tablefoo').map(row => {
	row.calc = 42;
	return row;

JavaScript/Bash source released under the MIT License.