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

control-timeout

v0.2.0

Published

A timeout class for controlling one or multiple timeouts

Downloads

6

Readme

#control-timeout

####A timeout class for controlling one or multiple timeouts.

###Features:

  • register one or multiple timeouts within the same context
  • start or stop a specific timeout, or all at once
  • add to or remove timeouts from the context at any time
  • have a common delay or override it for specific timeouts
  • provides logs for invalid input errors, or can use your own preferred logger
  • dynamically type safe

###Usage

First install: npm install --save control-timeout

// require the class
var Timeout= require( 'control-timeout' );

// you can change the timeout class default overall fallback delay time of 0 seconds
Timeout.delay= 10000; // milliseconds

// create a timeout instance/context and override the class default delay by
// passing a delay time that will be used as a fallback for all timeouts only in this instance
var timeout= new Timeout( 3000 );

// add a timeout to the context without running it right away
var first= timeout.add({
	 id		: 'first'
	 // declare an action to be taken in case the timeout is reached
	,action	: () => console.log( 'first timeout has been triggered' )
});

// run it only when you need it
// this will start the timeout using the default context's 3000ms delay time
timeout.run( 'first' );
// first timeout has been triggered

// add a second timeout, this time overriding the default context delay
var second= timeout.add({
	 id		: 'second'
	 // receive arguments passed by .run()
	,action	: ( msg1, msg2 ) => console.log( 'second timeout, message:', msg1+ msg2 )
	// override the context default delay time for this specific timeout
	,delay	: 1000
});

// pass arguments to the timeout via the run method, after the id argument
timeout.run( 'second', 'hello arguments', '!')
// second timeout, message: hello arguments!


// calling run with a falsey first argument causes to start all timeouts in the context
timeout.run( null, 'generic', ' message..' );

// you can stop one or multiple timeouts from running
timeout.stop( 'first', 'second' );

// or you can stop all by not giving a specific name
timeout.stop();

// you can remove one or multiple timeouts from the context with remove
timeout.remove( 'first', 'second' );

// NOTE: removing timeouts also stops them if they are running

// or remove all registered timeouts at once
timeout.removeAll()


// you can also add a timeout like this
timeout.add( 'third', () => timeout.stop('first'), 2000 );


// you can change the delay of a specific timeout for it's following runs
timeout.setDelay( 'first', 1000 );


// you can change the default log method by passing a custom handler
Timeout.setLog( (err) => {
	console.log( 'my custom input error handler', err );
});

// or turn logging of by calling setLog without arguments
Timeout.setLog();

The raw native setTimeout return value is only available after the .run mehtod has been called. So, if for some reason you need it, take run's return value:

// the run method returns the raw timeout
var rawSecond= timeout.run( 'second' );

// or all timeouts that are running, in an array
var timeouts= timeout.run();

// use getTimeout to get the raw timeout value of a running timeout
var rawFirst= timeout.getTimeout( 'first' );

change log

0.1.0

  • .add prototype now returns the context
  • adds babel transpiler as dev dependency for better cross browser compatibility

###license

MIT