bluebird

Resolve *and* reject all promises in Bluebird

血红的双手。 提交于 2019-12-22 17:55:47
问题 I'm looking for the way to get both resolutions and rejections from promise array. I'm currently counting on Bluebird implementation, so ES6 compatible solution would be suitable, too. The best thing that comes to mind is to use Bluebird's Promise.settle for that, and I consider promise inspections an unnecessary complication here: let promises = [ Promise.resolve('resolved'), Promise.resolve('resolved'), Promise.reject('rejected') ]; // is there an existing way to do this? let

Promise version of a “while” loop?

删除回忆录丶 提交于 2019-12-22 12:45:14
问题 I've come to the realization that since promises in ECMAScript 6 allow for synchronous coding of asynchronous functions, for every promise-laden piece of code there's a synchronous corollary. For instance: var data = processData(JSON.parse(readFile(getFileName()))); Is the same as: var data = getFileName() .then(readFile) .then(JSON.parse) .then(processData); Now for my current use-case I want to write code to pull data from a massive public API. The API is paginated, so in a purely

Equivalent of BlueBird Promise.props for ES6 Promises?

匆匆过客 提交于 2019-12-22 04:49:19
问题 I would like to wait for a map of word to Promise to finish. BlueBird has Promise.props which accomplishes this, but is there a clean way to do this in regular javascript? I think I can make a new object which houses both the word and the Promise, get an array of Promises of those objects, and then call Promise.all and put them in the map, but it seems like overkill. 回答1: If you are dealing with a Map with values that are promises (or a mix of promises and non-promises) - and you want the

bluebird promise.method to wraps a function return a promise,is that ok?

情到浓时终转凉″ 提交于 2019-12-22 03:51:49
问题 using bluebird in my code , and I use promise.method to cover a original functions just like the api say.Then I write a function which return a promise,and use promise.method to cover it.Those two function return the same: function () { var ret = new Promise(INTERNAL); ret._captureStackTrace(); ret._pushContext(); var value = tryCatch(fn).apply(this, arguments); ret._popContext(); ret._resolveFromSyncValue(value); return ret; } Is it ok to use promise.method to cover the function return a

ES6 Promise / Typescript and the Bluebird Promise

独自空忆成欢 提交于 2019-12-22 02:06:10
问题 I have a nodejs / typescript 2 project and use the es6-promise package. Now i would like to get rid of the extra package because i can target ES6 in typescript directly. So i removed the es6-promise package and changed the tsconfig.json to target es6. { "compilerOptions": { "target": "es6", // ... } } Many 3rd party packages uses the Bluebird promise but the promise definition is incompatible to the default es6 promise as stated on different posts on github bluebird 3.0 definifion is not

Passing Variables Through a Promise Chain [duplicate]

一笑奈何 提交于 2019-12-21 09:31:51
问题 This question already has an answer here : How to chain and share prior results with Promises [duplicate] (1 answer) Closed 2 years ago . Is there a better way to do this? let foo; return functionA().then(result => { foo = result; return functionB(); }).then(bar => { return functionC(foo, bar); }); Notice that the result of functionA is required input to functionC . Using a variable outside the promise scope works fine, but it feels kinda icky. Is there a clean idiomatic way to do this?

Passing Variables Through a Promise Chain [duplicate]

大城市里の小女人 提交于 2019-12-21 09:30:12
问题 This question already has an answer here : How to chain and share prior results with Promises [duplicate] (1 answer) Closed 2 years ago . Is there a better way to do this? let foo; return functionA().then(result => { foo = result; return functionB(); }).then(bar => { return functionC(foo, bar); }); Notice that the result of functionA is required input to functionC . Using a variable outside the promise scope works fine, but it feels kinda icky. Is there a clean idiomatic way to do this?

Mongodb node driver 2.0.* with Bluebird 2.9.* promisification

懵懂的女人 提交于 2019-12-21 09:16:51
问题 So there are a few other queries around this subject such as: How can I promisify the MongoDB native Javascript driver using bluebird? However it does not seem to address the latest version of the driver, which seems to have issues when trying to promisify. Currently I can get the MongoClient working by doing: Promise.promisifyAll(mongodb.MongoClient); // Using .Prototype here fails to promisify However no matter what I try the Collections do not seem to operate using the *async calls, it may

Node.js bulk download and Bluebird promises

烈酒焚心 提交于 2019-12-21 06:38:13
问题 I'm writing a bulk downloader for node.js and trying to understand bluebird promises. I want to limit the number of parallel requests and disk writes. As I understand it, Promise.map() with {concurrent: } should do what I want. Because pipe() and http.get() can't automatically be promisified, I'm trying to use custom promises. But I don't fully understand the then() mechanism. To me, it sounds like the returned promise should only be fulfilled when the whole chain has been fulfilled. However,

Parallel operations with Promise.all?

梦想的初衷 提交于 2019-12-21 03:33:32
问题 I'm led to believe that Promise.all executes all the functions you pass it in parallel and doesn't care what order the returned promises finish. But when I write this test code: function Promise1(){ return new Promise(function(resolve, reject){ for(let i = 0; i < 10; i++){ console.log("Done Err!"); } resolve(true) }) } function Promise2(){ return new Promise(function(resolve, reject){ for(let i = 0; i < 10; i++){ console.log("Done True!"); } resolve(true) }) } Promise.all([ Promise1(),