HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
cujojs
when
JavaScript2012–2014
cujojs / when

when

A solid, fast Promises/A+ and when() implementation, plus other async goodies.

6Distinct people
6Mentions
1Explicit recommenders
3.4KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

A solid, fast Promises/A+ and when() implementation, plus other async goodies.

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

So can when.js which has become my favorite promises library: https://github.com/cujojs/when http://know.cujojs.com/tutorials/async/mastering-async-error...

rymohr used a recommendation phrase. One indexed comment matches. This is a phrase match, not a verdict.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 12:54:37 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by month6 dated mentions

Observed mentions: 2012-07-12 17:09:32 UTC to 2014-11-26 18:06:30 UTC.

0122012-07-01 00:00:00 UTC to 2012-08-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 commentsJul 20122012-08-01 00:00:00 UTC to 2012-09-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2012-09-01 00:00:00 UTC to 2012-10-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2012-10-01 00:00:00 UTC to 2012-11-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2012-11-01 00:00:00 UTC to 2012-12-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2012-12-01 00:00:00 UTC to 2013-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2013-01-01 00:00:00 UTC to 2013-02-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2013-02-01 00:00:00 UTC to 2013-03-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2013-03-01 00:00:00 UTC to 2013-04-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2013-04-01 00:00:00 UTC to 2013-05-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2013-05-01 00:00:00 UTC to 2013-06-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2013-06-01 00:00:00 UTC to 2013-07-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2013-07-01 00:00:00 UTC to 2013-08-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2013-08-01 00:00:00 UTC to 2013-09-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2013-09-01 00:00:00 UTC to 2013-10-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 commentsSep 20132013-10-01 00:00:00 UTC to 2013-11-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2013-11-01 00:00:00 UTC to 2013-12-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2013-12-01 00:00:00 UTC to 2014-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2014-01-01 00:00:00 UTC to 2014-02-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2014-02-01 00:00:00 UTC to 2014-03-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2014-03-01 00:00:00 UTC to 2014-04-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2014-04-01 00:00:00 UTC to 2014-05-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2014-05-01 00:00:00 UTC to 2014-06-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2014-06-01 00:00:00 UTC to 2014-07-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2014-07-01 00:00:00 UTC to 2014-08-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2014-08-01 00:00:00 UTC to 2014-09-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2014-09-01 00:00:00 UTC to 2014-10-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2014-10-01 00:00:00 UTC to 2014-11-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2014-11-01 00:00:00 UTC to 2014-12-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 commentsNov 2014

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
Jul 20122012-07-01 00:00:00 UTC2012-08-01 00:00:00 UTC101
Aug 20122012-08-01 00:00:00 UTC2012-09-01 00:00:00 UTC000
Sep 20122012-09-01 00:00:00 UTC2012-10-01 00:00:00 UTC000
Oct 20122012-10-01 00:00:00 UTC2012-11-01 00:00:00 UTC202
Nov 20122012-11-01 00:00:00 UTC2012-12-01 00:00:00 UTC000
Dec 20122012-12-01 00:00:00 UTC2013-01-01 00:00:00 UTC000
Jan 20132013-01-01 00:00:00 UTC2013-02-01 00:00:00 UTC000
Feb 20132013-02-01 00:00:00 UTC2013-03-01 00:00:00 UTC000
Mar 20132013-03-01 00:00:00 UTC2013-04-01 00:00:00 UTC000
Apr 20132013-04-01 00:00:00 UTC2013-05-01 00:00:00 UTC000
May 20132013-05-01 00:00:00 UTC2013-06-01 00:00:00 UTC000
Jun 20132013-06-01 00:00:00 UTC2013-07-01 00:00:00 UTC000
Jul 20132013-07-01 00:00:00 UTC2013-08-01 00:00:00 UTC000
Aug 20132013-08-01 00:00:00 UTC2013-09-01 00:00:00 UTC000
Sep 20132013-09-01 00:00:00 UTC2013-10-01 00:00:00 UTC000
Oct 20132013-10-01 00:00:00 UTC2013-11-01 00:00:00 UTC000
Nov 20132013-11-01 00:00:00 UTC2013-12-01 00:00:00 UTC000
Dec 20132013-12-01 00:00:00 UTC2014-01-01 00:00:00 UTC101
Jan 20142014-01-01 00:00:00 UTC2014-02-01 00:00:00 UTC000
Feb 20142014-02-01 00:00:00 UTC2014-03-01 00:00:00 UTC000
Mar 20142014-03-01 00:00:00 UTC2014-04-01 00:00:00 UTC000
Apr 20142014-04-01 00:00:00 UTC2014-05-01 00:00:00 UTC101
May 20142014-05-01 00:00:00 UTC2014-06-01 00:00:00 UTC000
Jun 20142014-06-01 00:00:00 UTC2014-07-01 00:00:00 UTC000
Jul 20142014-07-01 00:00:00 UTC2014-08-01 00:00:00 UTC000
Aug 20142014-08-01 00:00:00 UTC2014-09-01 00:00:00 UTC000
Sep 20142014-09-01 00:00:00 UTC2014-10-01 00:00:00 UTC000
Oct 20142014-10-01 00:00:00 UTC2014-11-01 00:00:00 UTC000
Nov 20142014-11-01 00:00:00 UTC2014-12-01 00:00:00 UTC101

What Hacker News says

6 sources
It's honestly not as much of an issue as it's often made out to be. There are a ton of ways to manage asynchronous code out there including but not limited to all the various promise libraries such as when.js(https://github.com/cujojs/when), q (https://github.com/kriskowal/q), and bluebird (https://github.com/petkaantonov/bluebird). Not to mention the Async library (https://github.com/caolan/async) which is full of tools to help manage it. As for blocking, it's something you deal with. Realistically speaking if you're doing CPU intensive tasks then Node is definitely the wrong solution. However, if you're doing tasks that are IO oriented then Node is fantastic.
In Yahoo Mail moving to React
This article made it click for me. I had read several others that went over my head. The point of promises, as explained in this article, is to mirror the error handling semantics of synchronous code with minimal boilerplate. In code based on callbacks, if an error occurs somewhere, you must either deal with it locally or pass it along the callback chain manually. Promises mimic the try/catch system. Here's a variation based on the first example in the WhenJS documentation[0]. It demonstrates the basic control flow, we'll see later why it makes error handling easier: function loadImage (src) { var deferred = when.defer(), img = document.createElement('img'); img.onload = function () { deferred.resolve(img); }; img.onerror = function () { deferred.reject(new Error('
Read the rest
Image not found: ' + src)); }; img.src = src; // Return only the promise, so that the caller cannot // resolve, reject, or otherwise muck with the original deferred. return deferred.promise; } // example usage: loadImage('http://google.com/favicon.ico').then( function gotIt(img) { document.body.appendChild(img); return aSecondPromise; }, function doh(err) { document.body.appendChild(document.createTextNode(err)); } ).then(function(/*resolved value of the second promise*/){...}); First, lets focus on the `loadImage()` function, which wraps an async image load into a promise object. It first creates a deferred object wich has two methods and one property: * `defered.promise` is an objet with a `then` method that takes two optional handlers (success,error), which returns another promise. This allows chaining (more on that later). * `defered.resolve(result)` resolves the corresponding promise: it takes one parameter and passes it to the success handler. * `reject(error)` has similar behaviour but for the error handler. These two methods are mutually exclusive. If you call one, you can't call the other. As you can see, `loadImage()` defines two event handlers for the img object, that will either resolve or reject the promise. It schedules the async event, then returns the promise object. The `then` method of the latter registers two handlers one of which will kick in when the async call resolves the promise. -- There's no point in using promises for trivial code like this. Their usefulness comes from subtleties in the way the `then()` methods propagate the successes and errors when they are chained. Success and error handlers are optional. If at a given step a success/error should have been triggered but isn't, the value is passed to the next one of the same kind in the then chain. Let's take the example in this article: getTweetsFor("domenic") // promise-returning async function .then(function (tweets) { var shortUrls = parseTweetsForUrls(tweets); var mostRecentShortUrl = shortUrls[0]; return expandUrlUsingTwitterApi(mostRecentShortUrl); // promise-returning async function }) .then(doHttpRequest) // promise-returning async function .then( function (responseBody) { console.log("Most recent link text:", responseBody); }, function (error) { console.error("Error with the twitterverse:", error); } ); At each step, the promise can be resolved or rejected. If it is resolved, its result is passed to the next success handler. If if is rejected at any step, the following OK steps are skipped, and the error ends up being handled by the error handler defined in the last then clause. It is thus equivalent to this synchronous code: try { var tweets = getTweetsFor("domenic"); // blocking var shortUrls = parseTweetsForUrls(tweets); var mostRecentShortUrl = shortUrls[0]; var responseBody = doHttpRequest(expandUrlUsingTwitterApi(mostRecentShortUrl)); // blocking x 2 console.log("Most recent link text:", responseBody); } catch (error) { console.error("Error with the twitterverse: ", error); } Imagine how messy it would be to propagate the errors in standard callback-based code... -- One last thing about handlers: loadImage(src).then/*1*/(successH, errorH).then/*2 */(successH2, errorH2); loadImage() returns a first promise and its `then1()` method registers the handlers and returns a promise, whose state will depend on the behaviour of the handlers once one of them is triggered. If the handler (either successH or errorH) returns a value, the promise will pass that value to the next success handler. If the handler throws an exception, the value thrown will be passed to the next error handler, and so on. This brings us the following parallel, FTA: 1. Promise fulfilled, fulfillment handler returns a value: simple functional transformation 2. Promise fulfilled, fulfillment handler throws an exception: getting data, and throwing an exception in response to it 3. Promise rejected, rejection handler returns a value: a catch clause got the error and handled it 4. Promise rejected, rejection handler throws an exception: a catch clause got the error and re-threw it (or a new one) At last, a handler can return a new promise. In that case, the handler that is called next will depend on whether that promise is resolved or rejected. -- Sigh... I'm done. I hope I didn't make things more confusing. -- [0] https://github.com/cujojs/when/wiki/Examples
In Missing the Point of Promises

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.