@truffle/promise-tracker

A tool for wrangling async operations that need to complete before the truffle process exits

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
Last updated 3 years ago by cliffoo .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @truffle/promise-tracker 
SYNC missed versions from official npm registry.

@truffle/promise-tracker

This library is used for keeping track of asynchronous work that needs to complete prior to the process exiting.

Usage

IMPORTANT Only use this library as a last resort. Typically you're better off architecting things so that you don't need process-level tracking of outstanding tasks.

Some alternatives to consider before using this module:

  • Wherever possible, only make asynchronous calls from within an asynchronous context (aka, avoid using .then and .catch callbacks).
  • Implement timeouts for long-running processes using Promise.race
  • Unref any best-effort/speculative timers (immediate, timeout to prevent them from keeping your process alive when everything else is done

Tracking asynchronous operations

For the moment promise tracking is implemented as a method decorator, meaning it must be applied to method declaration on a class.

It can be applied to any method, and it will only add special handling when methods return promises

import { tracked } from "@truffle/promise-tracker";

class Foo {
  // totally fine, even though it doesn't return a promise
  @tracked
  synchronousBar(): "-" {
    return "-";
  }

  @tracked
  async asyncBar(): Promise<"-"> {
    return "-";
  }

  // this works the same as with `asyncBar`, even though it's not explicitly an
  // async method
  @tracked
  promiseBar(): Promise<"-"> {
    return new Promise<"-">(resolve => resolve("-"));
  }
}

Waiting for tracked operations to complete (async)

import { waitForOutstandingPromises } from "@truffle/promiseTracker";

let exitCode = 0;

// If no catchHandler is passed, rejected promises are handled silently.
// This is because these promise rejections should already be handled by the
// caller that created the promise.
await waitForOutstandingPromises({ catchHandler: () => (exitCode = 1) });
process.exit(exitCode);

Waiting for tracked operations to complete (synchronous)

import { waitForOutstandingPromises } from "@truffle/promiseTracker";

let exitCode = 0;

// If no catchHandler is passed, rejected promises are handled silently.
// This is because these promise rejections should already be handled by the
// caller that created the promise.
waitForOutstandingPromises({ catchHandler: () => (exitCode = 1) }).then(() => {
  process.exit(exitCode);
});

Current Tags

  • 0.1.7                                ...           latest (a year ago)
  • 0.1.0-alpha.2                                ...           signTypedData_v4 (3 years ago)
  • 0.1.1-typescript-migrations.0                                ...           typescript-migrations (2 years ago)

11 Versions

  • 0.1.7 [deprecated]           ...           a year ago
  • 0.1.6 [deprecated]           ...           2 years ago
  • 0.1.5 [deprecated]           ...           2 years ago
  • 0.1.4 [deprecated]           ...           2 years ago
  • 0.1.3 [deprecated]           ...           2 years ago
  • 0.1.2 [deprecated]           ...           2 years ago
  • 0.1.1 [deprecated]           ...           2 years ago
  • 0.1.1-typescript-migrations.0 [deprecated]           ...           2 years ago
  • 0.1.0-alpha.2 [deprecated]           ...           3 years ago
  • 0.1.0 [deprecated]           ...           3 years ago
  • 0.1.0-alpha.0 [deprecated]           ...           3 years ago
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (6)

© 2010 - cnpmjs.org x YWFE | Home | YWFE