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 🙏

© 2026 – Pkg Stats / Ryan Hefner

promisetimeout

v0.0.2

Published

Adds a lifecycle to a Promise.

Downloads

28

Readme

PromiseTimeOut

This lib helps you to deal with Promises that have a lifetime limit regardless the implementation.


What is a Promise ?

Promise its a solution that triggers an event after its execution. It can be a success function or fail function. Its normally used for async calls.

It patterns looks this way:

#!javascript

var promise = new Promise(function(resolve, reject) {
		//do async
		if(ok) {  
			resolve(myData); 
		} else { 
			reject(myError); 
		}
	});
	var	successCallback = function(myData) {
	   console.log("Success! ", myData);
    };
    var errorCallback = function(myError) {
		console.log("Failed! ", myError);
	}
	promise.then(successCallback, errorCallback);

How it looks PromiseTimeOut

There are only 3 differences:

  1. Adition of parameters timeOut and message.

  2. The async function now receive an object holder that contains resolve and reject functions.

  3. In errorCallback, now you have an object that represents timeOut.

#!javascript

var timeOut = 3000; //3s
	var message = "You have only 3s to execute it!";

	var promise = new PromiseTimeOut(function(holder) {
		//do async
		if(ok) {  
			holder.resolve(myData); 
		} else { 
			holder.reject(myError); 
		}
	}, timeOut, message);
	
	var	successCallback = function(myData) {
	   console.log("Success! ", myData);
    };
    var errorCallback = function(myError) {
	    if(myError.timeOut) {
		    console.log(myError.message); // You have only 3s to execute it!
		} else {
			console.log("Failed! ", myError);
		}
	}
	promise.then(successCallback, errorCallback);

Motivation

It was born due to the construction of a lib that let the developer deal with an Promise - he can do whatever he wants, but if the developer have forgotten to put the resolve() function, the whole application would stop and probably it would take a long time to see what is the problem. With this solution, I can warn the developer: "Have you remembered to put resolve() ?"

Complete examples

Your execution is faster than the timeout

#!javascript

new PromiseTimeOut(function (holder) {
		console.log("[B] Searching...");
		
		timer.wait(1000).then(function () {
			holder.resolve({ 'info': 'info "B"' });
		});
	}, 2000, "[B] time > 2 seconds.").then(
		function (success) {
			console.log("[B] Success: " + success.info);
		}, function (err) {
			console.log("[B] Error: " + err.message);
		}
	);

Result:

[B] Searching...
[B] Success: info "B"

Your execution is faster than the timeout

#!javascript

var timer = require("./timer")();
	new PromiseTimeOut(function (holder) {

		console.log("[A] Searching...");
	
		timer.wait(4000).then(function () {
			holder.resolve({ 'info': ' info "A"' });
		});
	}, 3000, "[A] time > 3 seconds.").then(
		function (success) {
			console.log("[A] Success: " + success.info);
		}, function (err) {
			console.log("[A] Error: " + err.message);
		}
	);

Result:

[A] Searching...
[A] Error: [A] time > 3 seconds.

Two executions simultaneous

A needs 4 seconds to execute, but has only 3s. It will happen timeOut. B needs 1 second to execute and has 2s. It will return its message.

#!javascript

var PromiseTimeOut = require("./promiseTimeOut");
	var timer = require("./timer")();
	
	new PromiseTimeOut(function (holder) {
		console.log("[A] Searching...");
		timer.wait(4000).then(function () {
			holder.resolve({ 'info': ' info "A"' });
		});
	}, 3000, "[A] time > 3 seconds.").then(
		function (success) {
			console.log("[A] Success: " + success.info);
		}, function (err) {
			console.log("[A] Error: " + err.message);
		}
	);
	
	//Need to instanciate again to work.
	timer = require("./timer")();
	
	
	new PromiseTimeOut(function (holder) {
		console.log("[B] Searching...");
		
		timer.wait(1000).then(function () {
			holder.resolve({ 'info': 'info "B"' });
		});
	
	}, 2000, "[B] time > 2 seconds.").then(
		function (success) {
			console.log("[B] Success: " + success.info);
		}, function (err) {
			console.log("[B] Error: " + err.message);
		}
	);

Results

[A] Searching...
[B] Searching...
[B] Success: info "B"
[A] Error: [A] time > 3 seconds.

Requirements

This lib is based in Promise lib. You can know more about here: https://www.npmjs.com/package/promise