JSPM

@solana/promises

2.0.0-canary-20240902085237
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 246505
  • Score
    100M100P100Q175101F
  • License MIT

Helpers for using JavaScript promises

Package Exports

  • @solana/promises

Readme

npm npm-downloads semantic-release
code-style-prettier

@solana/promises

This package contains helpers for using JavaScript promises.

Functions

getAbortablePromise(promise, abortSignal?)

Rejects if the abortSignal is aborted before the promise settles. Resolves or rejects with the value of the promise otherwise.

const result = await getAbortablePromise(
    // Resolves or rejects when `fetch` settles.
    fetch('https://example.com/json').then(r => r.json()),
    // ...unless it takes longer than 5 seconds, after which the `AbortSignal` is triggered.
    AbortSignal.timeout(5000),
);

safeRace(...promises)

An implementation of Promise.race that causes all of the losing promises to settle. This allows them to be released and garbage collected, preventing memory leaks.

Read more here: https://github.com/nodejs/node/issues/17469