es6-promise

Promise.all([]) returns a resolved promise, but Promise.race([]) returns a pending promise. Why are they different?

老子叫甜甜 提交于 2019-12-25 02:23:06
问题 If either Promise.all or Promise.race are called with a non-empty array, they return a pending promise: console.log(Promise.all([1])); // prints Promise {<pending>} console.log(Promise.race([1])); // returns Promise {<pending>} If Promise.race is called with an empty array, it returns a pending promise: console.log(Promise.race([])); // prints Promise {<pending>} But if Promise.all is called with an empty array, it returns a promise that is already resolved: console.log(Promise.all([])); //

Using promise to work with web worker inside a JavaScript closure

泄露秘密 提交于 2019-12-25 00:01:46
问题 I was executing an image processing operation in JavaScript which was working as expected expect one thing that sometimes it was freezing the UI, which made me to use Web worker to excute the image processing functions. I have a scenario where i need to process multiple. Below is a summary of workflow which i am using to achieve the above feat. //closure var filter = (function(){ function process(args){ var promise = new Promise(function (resolve, reject) { if (typeof (Worker) !== "undefined"

How to render value in promises on button click in react?

非 Y 不嫁゛ 提交于 2019-12-24 22:33:49
问题 I have two modules App.jsx import React from 'react'; import ReactDOM from 'react-dom'; import {accounts} from './contract.jsx'; class App extends React.Component{ constructor(props){ super(props); this.state={'text':'','accounts':'','clicked':false}; } componentDidMount = () => { this.setState({'accounts':accounts()}); } buttonAction = (e) => { this.setState({'clicked':true}); } render(){ return( <div align="center"> <Button name="get all Accounts" action={this.buttonAction}/> {this.state

Failing to convert a callback queue to use promises

ε祈祈猫儿з 提交于 2019-12-24 21:20:39
问题 I've been using promises + async/await for some time now, I thought I was comfortable with them, but this situation really has me stumped. Any advice/guidance is greatly appreciated! Context: My app is making URI requests, but I have to delay each request by a couple seconds. To make the delay more exact, I set up a queue for making the requests. No problem using callbacks, but I've been at it for a while, and I can't seem to wrap my head around how to pull it off using promises. Sandboxed

Type definition of Promise.all doesn't match with the docs

社会主义新天地 提交于 2019-12-24 19:53:10
问题 Looking at the type definition of Promise.all, I see 10 definitions: /** * Creates a Promise that is resolved with an array of results when all of the provided Promises * resolve, or rejected when any Promise is rejected. * @param values An array of Promises. * @returns A new Promise. */ all<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>; I only included the one with an array of length 3, but there also exist all<T1> , all<T1, T2

How to correctly trap and read any errors generated in a Promise.all call? [duplicate]

丶灬走出姿态 提交于 2019-12-24 19:27:59
问题 This question already has answers here : Wait until all promises complete even if some rejected (17 answers) Closed 10 months ago . I currently have a node.js/graphql micro service that uses Promise.all to call another micro service via apolloFetch. My Promise.all part seems to be working ok but I'm trying to have the error logging part working. I need to make sure that the Promise.all executes ALL THE PROMISES and not quit after it encounters the first error. Once it executes ALL THE

How to return an array received from fetching api data in a .then statement?

*爱你&永不变心* 提交于 2019-12-24 18:58:31
问题 I'm trying to export an array inside a .then statement but its not working. I have no clue how to make it work otherwise. Actually I'm just trying to set my initial state in redux to this static data I am receiving from the movie database api. import { API_URL, API_KEY } from '../Config/config'; const urls = [ `${API_URL}movie/popular?api_key=${API_KEY}&language=en-US&page=1`, `${API_URL}movie/popular?api_key=${API_KEY}&language=en-US&page=2`, ] Promise.all(urls.map(items => { return fetch

'let' Keyword in Firefox 43.0.2 not working

Deadly 提交于 2019-12-24 16:03:44
问题 I have read where the 'let' keyword is working now in Firefox, and that the use of specifying the version in the script tag is no longer necessary. HOWEVER, despite adding strict mode, I am still getting the Firefox error: I'd tried block scoping strict mode, using the version in the script tag and nothing seems to be working. Any ideas on what may cause this persistent error for the 'let' keyword in Firefox? Or anything I may be able to eliminate as a cause? Thanx!!! 回答1: According to the

Triggering a route only after dispatch and commit completed in VueJS

六眼飞鱼酱① 提交于 2019-12-24 13:33:37
问题 I do have a form submit which takes email and password then pass them into an action in store called userSignIn SignIn.vue : onSubmit () { if (this.$refs.form.validate()) { const user = { email: this.email, password: this.password } this.$store.dispatch('userSignIn', user) .then(() => { this.$router.push('/') }).catch(err => { console.log(err) }) } } Within store, I do have a userSignIn action like this store.js actions: userSignIn ({commit, getters}, payload) { getters.Api.post(`user/signin`

How to Polyfill Promise in Visual Studio 2017 Office Add-in TypeScript Project

非 Y 不嫁゛ 提交于 2019-12-24 11:37:18
问题 I am using TypeScript in an Office Add-in, and I want to use async / await functions specifically. The project fails to compile with "TS2468 TypeScript Cannot find global value 'Promise'." I have read on here that I have to create a polyfill for Promise, but so far have not been able to figure out how to get a polyfill working in Visual Studio 2017. I am attempting to use core-js, and have installed it in to the project using npm install core-js. I can see core-js is installed under node