es6-promise

How to wait a Promise inside a forEach loop

我只是一个虾纸丫 提交于 2021-01-29 00:58:36
问题 I'm using some Promise() functions to fetch some data and I got stuck with this problem on a project. example1 = () => new Promise(function(resolve, reject) { setTimeout(function() { resolve('foo1'); }, 3000); }); example2 = () => new Promise(function(resolve, reject) { setTimeout(function() { resolve('foo2'); }, 3000); }); doStuff = () => { const listExample = ['a','b','c']; let s = ""; listExample.forEach((item,index) => { console.log(item); example1().then(() => { console.log("Fisrt"); s =

How to wait a Promise inside a forEach loop

Deadly 提交于 2021-01-29 00:56:23
问题 I'm using some Promise() functions to fetch some data and I got stuck with this problem on a project. example1 = () => new Promise(function(resolve, reject) { setTimeout(function() { resolve('foo1'); }, 3000); }); example2 = () => new Promise(function(resolve, reject) { setTimeout(function() { resolve('foo2'); }, 3000); }); doStuff = () => { const listExample = ['a','b','c']; let s = ""; listExample.forEach((item,index) => { console.log(item); example1().then(() => { console.log("Fisrt"); s =

Why does this simple JS promise return a promise? [duplicate]

混江龙づ霸主 提交于 2021-01-28 10:06:56
问题 This question already has answers here : How to return value from an asynchronous callback function? [duplicate] (3 answers) Closed 1 year ago . A really simply question. I've boiled it down to the simplest version that illustrates my problem. Why does this vanilla JS return a promise, and how can I get it to return "Hello"? let result = test() .then(function(result) { return result; }); alert(result); function test(serialized) { return new Promise(function(resolve, reject) { resolve("Hello")

Why does this simple JS promise return a promise? [duplicate]

删除回忆录丶 提交于 2021-01-28 09:54:34
问题 This question already has answers here : How to return value from an asynchronous callback function? [duplicate] (3 answers) Closed 1 year ago . A really simply question. I've boiled it down to the simplest version that illustrates my problem. Why does this vanilla JS return a promise, and how can I get it to return "Hello"? let result = test() .then(function(result) { return result; }); alert(result); function test(serialized) { return new Promise(function(resolve, reject) { resolve("Hello")

Task Queue error with task : Cannot read property of undefined

血红的双手。 提交于 2021-01-28 07:22:39
问题 I write component witch some caching functionallity. It is based on async storage. static getDiscounts(categoryAndPage) { return AsyncStorage.getItem(categoryAndPage); } so It returning a promise. So inside my funtion I call then on this promise. makeRemoteRequest() { this.setState({loading: true}); const page = this.state.page; const catId = this.props.navigation.state.params.categoryId; var discountCacheKey = `${catId}_${page}`; var discountsPromise = DiscountsCache.getDiscounts

ES6 Promise are sometimes not resolving

瘦欲@ 提交于 2021-01-27 11:29:53
问题 Context: A device is sending me data at regular interval. When I receive those data I have to process them and store them in a database. We use Node.js 6.11.0, and the library node-postgres to query the database. We store those data, then we do a bunch of operation on them. Since we have to wait for the database to finish storing them, we rely on ES6 promise. Here's a sample of the code. First, the part of the code where we are getting the data processData(data).then(result => {

JS: Executing events overlapping in time afteranother

半世苍凉 提交于 2021-01-25 04:05:20
问题 I receive events on-the-fly in the correct order in which I want to process them after another (as well on-the-fly - so don't "store" them first). The following example is not going to work as the function someEventOccured() could be called multiple times in a very close timespan. Thus, the execution of handleEvent would overlap in time (which I don't want). As I am writing to a file in handleEvent() I cannot have simultaneously execute the function and need to maintain the order... async

JS: Executing events overlapping in time afteranother

自闭症网瘾萝莉.ら 提交于 2021-01-25 04:02:48
问题 I receive events on-the-fly in the correct order in which I want to process them after another (as well on-the-fly - so don't "store" them first). The following example is not going to work as the function someEventOccured() could be called multiple times in a very close timespan. Thus, the execution of handleEvent would overlap in time (which I don't want). As I am writing to a file in handleEvent() I cannot have simultaneously execute the function and need to maintain the order... async

JS: Executing events overlapping in time afteranother

这一生的挚爱 提交于 2021-01-25 03:59:38
问题 I receive events on-the-fly in the correct order in which I want to process them after another (as well on-the-fly - so don't "store" them first). The following example is not going to work as the function someEventOccured() could be called multiple times in a very close timespan. Thus, the execution of handleEvent would overlap in time (which I don't want). As I am writing to a file in handleEvent() I cannot have simultaneously execute the function and need to maintain the order... async

Vue login function

血红的双手。 提交于 2021-01-07 06:58:44
问题 I'm trying to hook up my backend with JWT authentication to a login component in Vue. This is my Vuex action: userLogin({commit}, payload) { axios.post('/users/token/obtain/', { email: payload.email, password: payload.password, }) .then(response => { localStorage.setItem('access', response.data.access) localStorage.setItem('refresh', response.data.refresh) let body = JSON.parse(atob(response.data.access.split('.')[1])) commit('userLogin', { userToken: response.data.access, userEmail: body