or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-promise.mdes6-static-methods.mdextension-methods.mdindex.mdnodejs-integration.mdrejection-tracking.mdsynchronous-inspection.md
tile.json

tessl/npm-promise

Bare bones Promises/A+ implementation with essential extensions for readable, performant asynchronous operation handling.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/promise@8.1.x

To install, run

npx @tessl/cli install tessl/npm-promise@8.1.0

index.mddocs/

Promise

Promise is a bare bones implementation of the Promises/A+ specification designed for readable, performant code with minimal but essential extensions. It provides foundational promise functionality for JavaScript applications requiring reliable asynchronous operation handling with maximum compatibility and performance.

Package Information

  • Package Name: promise
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install promise

Core Imports

const Promise = require('promise');

For specific execution environments:

// For Node.js domains support
const Promise = require('promise/domains');

// For setImmediate optimization
const Promise = require('promise/setimmediate');

// ES6-only features
const Promise = require('promise/lib/es6-extensions');
// or require('promise/domains/es6-extensions');  
// or require('promise/setimmediate/es6-extensions');

// Core only (deprecated entry point)
const Promise = require('promise/core'); // Use promise/lib/core instead

Browser polyfill:

<script src="https://www.promisejs.org/polyfills/promise-6.1.0.js"></script>

Basic Usage

const Promise = require('promise');

// Create a new promise
const promise = new Promise(function (resolve, reject) {
  // Async operation
  setTimeout(() => {
    if (Math.random() > 0.5) {
      resolve('Success!');
    } else {
      reject(new Error('Failed'));
    }
  }, 1000);
});

// Handle the promise
promise
  .then(result => console.log(result))
  .catch(error => console.error(error));

Architecture

Promise implements the complete Promises/A+ specification with several key architectural decisions:

  • Performance Optimized: Uses asap library for optimal async scheduling
  • Standards Compliant: Full Promises/A+ specification implementation
  • Extensible: Modular design allowing selective feature inclusion
  • Environment Aware: Support for domains, setImmediate, and browser environments
  • Type Safe: Comprehensive TypeScript definitions included

Capabilities

Core Promise Implementation

Foundational Promise constructor and chaining methods following the Promises/A+ specification.

function Promise(executor);
Promise.prototype.then(onFulfilled, onRejected);

Core Promise

ES6 Static Methods

Standard ES6 Promise static methods for creating and combining promises.

Promise.resolve(value);
Promise.reject(reason);
Promise.all(iterable);
Promise.allSettled(iterable);
Promise.race(iterable);
Promise.any(iterable);

ES6 Static Methods

Extension Methods

Additional instance methods that extend the core Promise functionality.

Promise.prototype.catch(onRejected);
Promise.prototype.done(onFulfilled, onRejected);
Promise.prototype.finally(onFinally);

Extension Methods

Node.js Integration

Utilities for bridging callback-based APIs with promises in Node.js environments.

Promise.denodeify(fn, argumentCount);
Promise.nodeify(fn);
Promise.prototype.nodeify(callback, ctx);

Node.js Integration

Synchronous Inspection

Optional methods for synchronously inspecting promise state (disabled by default).

Promise.enableSynchronous();
Promise.disableSynchronous();

Synchronous Inspection

Rejection Tracking

Development utilities for tracking and debugging unhandled promise rejections.

const rejectionTracking = require('promise/lib/rejection-tracking');
rejectionTracking.enable(options);
rejectionTracking.disable();

Rejection Tracking

Types

/**
 * Promise constructor following Promises/A+ specification
 * @param {function} executor - Function with resolve and reject parameters
 */
function Promise(executor);

/**
 * Promise state values (internal)
 * 0 - pending
 * 1 - fulfilled  
 * 2 - rejected
 * 3 - adopted (follows another promise)
 */

/**
 * Result interface for fulfilled promises in allSettled
 * @typedef {Object} PromiseFulfilledResult
 * @property {"fulfilled"} status - Status indicator
 * @property {*} value - The fulfillment value
 */

/**
 * Result interface for rejected promises in allSettled  
 * @typedef {Object} PromiseRejectedResult
 * @property {"rejected"} status - Status indicator
 * @property {*} reason - The rejection reason
 */

/**
 * Union type for promise settlement results
 * @typedef {PromiseFulfilledResult|PromiseRejectedResult} PromiseSettledResult
 */