javascript - Return a Q Promise from an API Properly -


I am developing an API that will give me the promise back. The promise of return is made up of many other promises, so I am using Q.Al and / or Q.Letset. The problem I am running in is that this code is never completed (see test).

I hope that the addUsers should be able to call / fail / etc on whatever is coming back, which is a Q.all or Q.allSettlted

API :

  'strict experiment'; Var q = Required ('q'), demand = = (Required), user = requires ('../model/user'), _ = ('underscore') ; Var addUsers = function (user) {var prompts __map (user, function) (user new user); var prom ); Returns Q.allSettled (promises); }; Module.exports.addUsers = addUsers;   

Test:

  'strict experiment'; Var kraken = require ('kraken-js'), express = required ('express'), request = requires ('superstest'), required ('tea'). Should (), userApi = require ('.. / lib / userApi'), user = required ('../model/user'); Describe ('# User API Test', function () (This user should include an array of users using users of your users, function (done) {var users = []; var user1 = {firstName: 'test1 ', LastName:' test1 ', password:' abc123 ', email:' me1@here.com ', user name:' test1 '}; var user2 = {first name:' test2 ', lastName:' test2 ', password : 'Abc123' email: 'me2@here.com', user name: 'test2'}; var user3 = {first name: 'test3', last name: 'test3', password: 'abc123', email: 'me3 @ Here.com ', Username:' Test3 '}; users.push (user1); users.push (user2); users.push (use R3); // Call the API and handle the wired which is returned to the user API.UUsers (users) then (function (result) should be {(results); // other assumptions are made here ();}) .file (function (mistake) {done (err);}}});});    

I'm not a big fan of q . I think there is too much magic, so instead of the native (0.11.x on the node) promise instead.

But if I understood it right, there is a cover around the standard function call of the q nbind node.
Maybe I'll copy its behavior using the new Promise API.

  promise = function (back) New promise (work (solution, reject) {newUser.save (function (mistake, data) {if (mistake) return reject (error) solution (data) }}}}}}   

I assume that newUser is a model model, and newUSer.save only an error Callback with the parameter. Since data is undefined, probably q does not call the resolution with a false value.

Your test with this version of Will try to run them instead of addUsers .

  var promise = promise; expected ('es6-promise') Promise // polyfill, mongoose = require (' Mongoose '; function addUsers (user) {return Promise.all (users.map (function) (new promise (work (solution, reject) {var newUser = new user (user); newUser.save (function ) {If (mistake) return reject (fault) solution ()})}}}}}}}   

on the edge it looks like the cool child bluebird > Use this day to decide for their promise.
It has to handle major errors (which is a problem with the original promise) and allows custom build.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -