A lightweight Promise and when() implementation, plus other async goodies.
Questions tagged [when-js]
62 questions
0
votes
3 answers
Moving from when.js to ES6 Promises
I've been using when.js for promises in node.js. I have a function like the following:
function my_func() {
var d = when.defer();
// Async actions simulated with timeout
setTimeout(function() {
//...
if(error) {
…

Sean Lynch
- 2,852
- 4
- 32
- 46
0
votes
1 answer
How to cleanly extract a callback out of a when.js promise?
I need to pass a callback to a function whose signature is function('ui', {foo: bar, callback: callbackfn}). The function I want to pass is a When.js promise.
The best I've come up with:
var d = when.defer();
var p = when(d);
var q =…

Steve Bennett
- 114,604
- 39
- 168
- 219
0
votes
1 answer
when - Unexpected Promise chain with intermediate errors
I'm wondering if the following is a normal behavior?
Code
var when = require('when'); // I'm using when@3.7.4 node_modules/when
console.log("INIT");
when.promise(function(resolve, reject) {
return when.reject("false")
.then(function(ok) {
…

Boris
- 991
- 1
- 9
- 15
0
votes
2 answers
Idiomatically testing when.js promises with Jasmine
I'm writing some Jasmine unit tests for code that returns when.js promises. I keep finding myself writing code like this:
doMyThing().then(function(x) {
expect(x).toEqual(42);
done();
}).otherwise(function() {
expect(true).toBe(false);
…

Steve Bennett
- 114,604
- 39
- 168
- 219
0
votes
0 answers
Parse .each() does not work within when()
Parse.Cloud.define("bulkUpdateUserViewedTraces", function(request, response){
Parse.Cloud.useMasterKey();
var userQuery = new Parse.Query(Parse.User);
userQuery.limit(200);
var userCount = 0;
userQuery
.find(function…

RonnyKnoxville
- 6,166
- 10
- 46
- 75
0
votes
1 answer
Jasmine AJAX mock turns string into array
I'm trying to write a test suite around my AjaxRequest class, but when I'm trying to inspect the request body I get this test failure
FAILED TESTS:
AjaxRequest
#POST
✖ attaches the body to the response
PhantomJS 1.9.8 (Mac OS X 0.0.0)
…

perpetualjourney
- 64
- 6
0
votes
2 answers
Node.js/Javascript - nested promises and for loop with when.js
I am currently struggling with the control flow of promise (promise newbie!).
I make a call to Redis which returns an array object. I then iterate through each of the results and call back to Redis to get a value and wish to populate these in to a…

Ben
- 6,026
- 11
- 51
- 72
0
votes
1 answer
Control when a `.then()` callback fires
I have a long chain of promises that wind through a module of my code. I don't know beforehand how many promises I'll wind through, nor do I have scope from any one promise to any other other promise (meaning I can't do a Promise.join()).
My problem…

seebiscuit
- 4,905
- 5
- 31
- 47
0
votes
0 answers
How to use promises when I need the various return values
I have this function which uses promises and is working correctly:
parse: function (fileAsString, options) {
return when.promise(function(resolve, reject){
if (fileAsString.length) {
var metaData = options || {};
…

MJB
- 3,934
- 10
- 48
- 72
0
votes
3 answers
Can I untangle this nesting of 'when' promise invocations?
I'm new to the when.js javascript library, but I'm familiar with async programming in C#. That's why I find this code to be unwieldy:
filters.doFilter('filter1name', reqAndPosts).then(function(filter1) {
filters.doFilter('filter2name',…

Nilzor
- 18,082
- 22
- 100
- 167
0
votes
2 answers
Understanding promises in javascript using when library
I've been trying to wrap my head around asynchronous programming and the use of promises. To help understand them, I've written some trivial nested code, but have run into a snag.
Here's the code: http://pastebin.com/hBtk9vER
Make sure you install…

b1nd
- 370
- 6
- 12
0
votes
1 answer
Using whenjs with requirejs
I am unable to use requirejs with whenjs, it gives 404 errors about missing files when running the site. I'm following the instructions in the whenjs README:
Firstly, I run git submodule add https://github.com/cujojs/when when in the project root…

ian
- 12,003
- 9
- 51
- 107
0
votes
1 answer
Cleaning up promises (flattening and error handling)
I'm using the when library and have some code like this:
when.join(
database.then(function(db) {
return db.collection("incidents");
}).then(function(col) {
return col.idExists(incidentId);
}),
…

Heptic
- 3,076
- 4
- 30
- 51
0
votes
3 answers
What is the when.js equivalent of Q.js's "done()"?
In addition to then(), Q.js also has a done(). done() is usually called at the end of a promise chain, like this:
promise
.then(callback)
.then(callback)
.done(callback);
This will catch any rejections that were not handled by the previous then()s,…

Matt Zukowski
- 4,469
- 4
- 37
- 38
0
votes
2 answers
how to use jQuery.when() with multiple jsonp requests?
I have 2 cross domain jsonp requests that need to be completed before another method can be executed. So I tried the $.when() function
$.when(getX(), getY()).then(createXY);
getX() and getY() make $.ajax() requests to two different domains with…

E.A.
- 321
- 1
- 4
- 13