es6-promise

ES6 Promises/calling a function after multiple promises are fulfilled (can't use Promises.all) [duplicate]

荒凉一梦 提交于 2019-12-03 17:26:38
This question already has an answer here: Wait until all promises complete even if some rejected 17 answers I'm writing Javascript which needs these events to happen in this order: Fire off several API calls simultaneously Once all calls have completed and responses have returned, execute a line of code Sounds simple but the tricky part is that I can't use Promises.all() because I still want that line of code to execute after all promises have been fulfilled, successful or not. Unless I misunderstand Promises.all(), one failing would cause the line of code to not execute in then() and execute

Can I Transpile for ES6-ES5 without npm, VS, Node, etc. and just the JS code itself somehow?

放肆的年华 提交于 2019-12-03 16:27:44
I am trying to get Firefox to run a Promise in ES6 but run into the 'let' keyword triggering an error; SyntaxError: let is a reserved identifier Changing the script tag to include; type="application/javascript;version=1.7" did not work, so I am seeking to Transpile the code. My situation is that there is nothing being used except a text editor. No NPM, not Node or Angular, no Visual Studio, nothing. So when I investigated the Compilers, I saw no option to let me Transpile this code without any of these other tools/editors/etc. Is there an option where I do not have to learn, use, install,

fetch method is not defined using ES6 fetch in React

十年热恋 提交于 2019-12-03 11:43:15
hey guys I have a trouble with fetch functions in my first react js app. This is the structure of my project: hello-world -- app -- components -- main.jsx -- node_modules -- public -- build.js -- index.html -- package.json This is what I've installed using npm: npm install react react-dom babel-core babel-loader babel-preset-es2015 babel-preset-react webpack --save-dev npm install --save isomorphic-fetch es6-promise I use webpack webpack.config module.exports = { entry: './app/components/main.jsx', output: { path: './public/', filename: "build.js", }, module: { loaders: [ { exclude: /(node

Does JavaScript Promise.all have a callback that is fired when there are success AND failures [duplicate]

给你一囗甜甜゛ 提交于 2019-12-03 11:27:12
This question already has answers here : Wait until all promises complete even if some rejected (17 answers) Am I misunderstanding Promise.all? I have X promises in an array and i'm trying to aggregate the success/failure ratio of the array. Here is what I think I know: Promise.all takes an array of promises. If all of the promises succeed then the .then callback is ran. If one of the promises fail then the .catch callback is called and the argument passed in is the value of the single raised error. There is no callback fired which is the result of all the promises if some succeed and some

Karma, PhantomJS and es6 Promises

那年仲夏 提交于 2019-12-03 10:31:53
问题 I am writing a JavaScript library that uses the new es6 promises. I can test the library in Firefox because promises are defined. However, when I try to test my code with Karma and PhantomJS, I get the error Can't find variable: Promise. . I am guessing this is because the PhantomJS browser doesn't support es6 promises yet. How can I configure Karma to bring in the polyfill for promises? 回答1: You can pull in the Babel polyfill by simply installing Babel Polyfill: npm install --save-dev babel

JavaScript Promises and setTimeout

二次信任 提交于 2019-12-03 09:03:55
I have been playing with Promises, but I am having trouble understanding what is happening with the following code: function a() { return new Promise(function (resolve, reject) { resolve("hi from a!"); }); } function b() { return new Promise(function (resolve, reject) { setTimeout(function () { resolve("hi from b!"); }, 5000); }); } function c() { return new Promise(function (resolve, reject) { setTimeout(function () { resolve("hi from c!"); }, 1000); }); } a().then(function (resultFromA) { console.log("a() responded with: " + resultFromA); b(); }).then(function (resultFromB) { console.log("b(

What is the best general practice to timeout a function in promise [closed]

陌路散爱 提交于 2019-12-03 07:14:57
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . Promisify a function call with timeouts I have seen many resources provide similar examples of using Promise.race to timeout a function call within a given period of time. This is a very good example of how Promise.race can be used in practice. Here's some sample code: function

Promise.all find which promise rejected

送分小仙女□ 提交于 2019-12-03 06:13:54
In my code, I am using Promise.all() to run code asynchronously once some promises have all fulfilled. Sometimes, one promise will fail, and I'm not sure why. I would like to know which promise is failing. Passing a callback as a second parameter to the .then method does not help much, as I know that a promise is rejecting but not which promise is rejecting. A stack trace does not help either, as the first item is the Promise.all() 's error handler. A line number from the Error object passed to the first parameter of the second function passed to the try function of the Promise.all() is simply

How to chain a Promise.all with other Promises?

女生的网名这么多〃 提交于 2019-12-03 04:24:23
I want to execute my code in the following order: Promise 1 Wait for 1 to be done, then do Promise 2+3 at the same time Final function waits for Promise 2+3 to be done I'm having some trouble figuring it out, my code so far is below. function getPromise1() { return new Promise((resolve, reject) => { // do something async resolve('myResult'); }); } function getPromise2() { return new Promise((resolve, reject) => { // do something async resolve('myResult'); }); } function getPromise3() { return new Promise((resolve, reject) => { // do something async resolve('myResult'); }); } getPromise1()

Implementing Promise.series as alternative to Promise.all

左心房为你撑大大i 提交于 2019-12-03 00:23:40
I saw this example implementation of Promise.all - which runs all promises in parallel - Implementing Promise.all Note that the functionality I am looking for is akin to Bluebird's Promise.mapSeries http://bluebirdjs.com/docs/api/mapseries.html I am making an attempt at creating Promise.series, I have this which seems to work as intended ( it actually is totally wrong, don't use it, see answers ): Promise.series = function series(promises){ return new Promise(function(resolve,reject){ const ret = Promise.resolve(null); const results = []; promises.forEach(function(p,i){ ret.then(function(){