CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rsvp

A lightweight library that provides tools for organizing asynchronous code

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

RSVP.js

RSVP.js provides simple tools for organizing asynchronous code. It is a lightweight implementation of Promises/A+ specification that works in both Node.js and browsers (IE9+), bringing additional utilities beyond the standard ES6 Promise API.

Package Information

  • Package Name: rsvp
  • Package Type: npm
  • Language: JavaScript (ES5 compatible)
  • Installation: npm install rsvp

Core Imports

import RSVP from "rsvp";
import { Promise, all, hash, resolve, reject } from "rsvp";

For CommonJS:

var RSVP = require("rsvp");
var Promise = RSVP.Promise;

For browsers via CDN:

<script src="https://cdn.jsdelivr.net/npm/rsvp@4/dist/rsvp.min.js"></script>

Basic Usage

import { Promise, all, hash, resolve } from "rsvp";

// Create a promise
const promise = new Promise(function(resolve, reject) {
  // async operation
  setTimeout(() => resolve("Success!"), 1000);
});

promise.then(function(value) {
  console.log(value); // "Success!"
}).catch(function(error) {
  console.error(error);
});

// Wait for multiple promises
all([
  resolve(1),
  resolve(2),
  resolve(3)
]).then(function(values) {
  console.log(values); // [1, 2, 3]
});

// Work with object of promises
hash({
  users: fetchUsers(),
  posts: fetchPosts()
}).then(function(results) {
  console.log(results.users);
  console.log(results.posts);
});

Architecture

RSVP.js is built around several key components:

  • Promise Class: ES6-compliant Promise implementation with additional methods
  • Array Utilities: Functions for working with arrays of promises (all, allSettled, race, map, filter)
  • Object Utilities: Functions for working with objects containing promises (hash, hashSettled)
  • Node.js Integration: Utilities for converting callback-based functions to promises (denodeify)
  • Configuration System: Global configuration and instrumentation capabilities
  • Event System: EventTarget implementation for custom events and promise instrumentation
  • Async Scheduling: Cross-platform async scheduling using the best available method

Capabilities

Promise Class

Core Promise implementation following Promises/A+ specification with additional methods like finally.

class Promise {
  constructor(resolver: Function, label?: string);
  then(onFulfillment?: Function, onRejection?: Function, label?: string): Promise;
  catch(onRejection: Function, label?: string): Promise;
  finally(callback: Function, label?: string): Promise;
  
  static all(array: Array, label?: string): Promise;
  static race(array: Array, label?: string): Promise;
  static resolve(value?: any, label?: string): Promise;
  static reject(reason?: any, label?: string): Promise;
}

Promise Class

Array Promise Utilities

Functions for working with arrays of promises including parallel execution, racing, transformation, and filtering.

function all(array: Array, label?: string): Promise;
function allSettled(entries: Array, label?: string): Promise;
function race(array: Array, label?: string): Promise;
function map(promises: Array, mapFn: Function, label?: string): Promise;
function filter(promises: Array, filterFn: Function, label?: string): Promise;

Array Utilities

Object Promise Utilities

Functions for working with objects containing promises, useful for handling named async operations.

function hash(object: Object, label?: string): Promise;
function hashSettled(object: Object, label?: string): Promise;

Object Utilities

Node.js Integration

Convert Node.js callback-style functions to promise-returning functions for better async composition.

function denodeify(nodeFunc: Function, options?: boolean | Array): Function;

Node.js Integration

Configuration and Events

Global configuration system and event handling for instrumentation and debugging.

function configure(name: string, value?: any): any;
function on(...arguments): void;
function off(...arguments): void;

const EventTarget: {
  mixin(object: Object): Object;
  on(eventName: string, callback: Function): void;
  off(eventName: string, callback?: Function): void;
  trigger(eventName: string, options?: any, label?: string): void;
};

Configuration and Events

Utility Functions

Additional utility functions for promise creation, error handling, and async scheduling.

function resolve(value?: any, label?: string): Promise;
function reject(reason?: any, label?: string): Promise;
function defer(label?: string): Object;
function rethrow(reason: any): void;
function asap(callback: Function, arg?: any): void;
function async(callback: Function, arg?: any): void;

Utility Functions

Types

interface PromiseState {
  state: 'fulfilled' | 'rejected';
  value?: any;
  reason?: any;
}

interface DeferredObject {
  promise: Promise;
  resolve: Function;
  reject: Function;
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/rsvp@4.8.x
Publish Source
CLI
Badge
tessl/npm-rsvp badge