npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-context

v0.7.0

Published

Context type that carries deadlines, cancelation signals, and other request-scoped values.

Downloads

17

Readme

Context Build Status

Context type that carries deadlines, cancelation signals, and other request-scoped values.

Influenced by Go's context.

Documentation

Initialize a new context.

Options

  • deadline (Number, optional): time when request expires (milliseconds since Unix epoch)
  • timeout (Number, optional): duration in milliseconds until request expires
  • parent (Context, optional): parent context; inherits deadlines, cancelation signals, and properties

Emitted when the request exceeds it's deadline or is canceled.

This is only emitted once.

Emitted when the request is finished.

This is only emitted once.

Create and return a child context.

This accepts the same options as the context constructor and automatically sets the parent option.

Options

  • cancel (Boolean, default: true): inherit cancel/finish signals and deadline/timeout
  • values (Boolean, default: true): inherit values (shallow copy)

Cancel request immediately.

This is safe to call multiple times.

True after canceled.

Time in milliseconds when the request will be canceled if not finished.

Finish the request, this must be called at the end of the request.

It is safe to call multiple times.

True after finished.

Return context values.

If object is provided then the context values will be merged into it.

Example

var context = require('node-context');

function display(ctx, name) {
  ctx.once('cancel', function() {
    console.log('%s canceled after %d ms', name, new Date() - ctx.time);
  });

  ctx.once('finish', function() {
    console.log('%s finished', name);
  });
}

var parent = context();
parent.time = new Date();

var master = parent.create({ timeout: 1000 });

display(parent, 'parent');
display(master, 'master');
display(master.create({ timeout: 500 }), 'worker1');
display(master.create(), 'worker2');

process.on('beforeExit', function() {
  parent.end();
});

Output

worker1 canceled after 524 ms
worker1 finished
master canceled after 1007 ms
worker2 canceled after 1007 ms
worker2 finished
master finished
parent finished

License

This work is licensed under the MIT License (see the LICENSE file).