async-await

Return promise value from observable subsciption

孤人 提交于 2020-04-30 05:57:25
问题 Is there any chance to return from helpMe function value from getDataFromApi() ? So far every time i call this function i get "null" value. async function helpMe() { let promise = null; let sub = someService.someObservable.subscribe(async () => { promise = await getDataFromApi() }) subscriptions.push(sub) return promise; } The first goal is i need to store subscription in global sub array. The second goal is when i get response with status 400 - I dont want to open modal. Only when i get 200

Return promise value from observable subsciption

女生的网名这么多〃 提交于 2020-04-30 05:56:25
问题 Is there any chance to return from helpMe function value from getDataFromApi() ? So far every time i call this function i get "null" value. async function helpMe() { let promise = null; let sub = someService.someObservable.subscribe(async () => { promise = await getDataFromApi() }) subscriptions.push(sub) return promise; } The first goal is i need to store subscription in global sub array. The second goal is when i get response with status 400 - I dont want to open modal. Only when i get 200

How to enable async/await with babel with support for IE11

孤街浪徒 提交于 2020-04-29 23:41:20
问题 I am hoping to use async/await in my source code and have it transpiled by babel to something useable by >0.25% not dead . My head is spinning with the plethora of ways to attack this. Some are deprecated, some flat out don't work, and the one that I have gotten to work more than doubles the size of my library. I've tried using @babel/polyfill with @babel/plugin-transform-async-to-generator and it works well, but the library goes from ~500kB to ~1.1MB. I also tried leaving it to @babel/preset

How to enable async/await with babel with support for IE11

北慕城南 提交于 2020-04-29 23:36:49
问题 I am hoping to use async/await in my source code and have it transpiled by babel to something useable by >0.25% not dead . My head is spinning with the plethora of ways to attack this. Some are deprecated, some flat out don't work, and the one that I have gotten to work more than doubles the size of my library. I've tried using @babel/polyfill with @babel/plugin-transform-async-to-generator and it works well, but the library goes from ~500kB to ~1.1MB. I also tried leaving it to @babel/preset

How can I await an array of tasks and stop waiting on first exception?

大兔子大兔子 提交于 2020-04-27 04:34:28
问题 I have an array of tasks and I am awaiting them with Task.WhenAll. My tasks are failing frequently, in which case I inform the user with a message box so that she can try again. My problem is that reporting the error is delayed until all tasks are completed. Instead I would like to inform the user as soon as the first task has thrown an exception. In other words I want a version of Task.WhenAll that fails fast. Since no such build-in method exists I tried to make my own, but my implementation

Firebase Cloud Function Transaction write on firestore throws await as an error

感情迁移 提交于 2020-04-18 05:47:48
问题 When I try to carry out a transaction on firestore, it throws me an error Unexpected token admin on the below code exports.issueBook = functions.https.onCall(async(data, context) => { if (!(context.auth && context.auth.token.admin)) { throw new functions.https.HttpsError( 'unauthenticated', 'only authenticated Admins can Issue Books' ); } memberData = { name: data.issueData.memberName, no: data.issueData.memberNo, role: data.issueData.memberRole, } transactionData = { books: data.issueData

How to properly load global variable with async values(Reactjs)?

旧巷老猫 提交于 2020-04-17 22:10:28
问题 I'm trying to solve this problem that I can't seem to solve with stripe's API's So when creating a charge with their new version API they say that in the front end we should call loadStripe('publishable Key',{'Connected account ID'}) and set that to a const. now I dont undestand how are we supposed to get the ID that is stored somewhere say a database? As a reference please look at this and here (In Step 3 ...). What I'm currently doing is something like this import React from "react"; import

Re-calling useEffect after a failed api fetching request

谁说胖子不能爱 提交于 2020-04-17 20:38:13
问题 I am executing useEffect() to update a state with JSON data. However the fetch request sometimes fails, so I want to re-execute the useEffect hook if that happens: ... import React, {useState, useEffect} from 'react'; import {getJsonData} from './getJsonData'; const myApp = () => { var ErrorFetchedChecker = false; const [isLoading,setIsLoading] = useState(true); const [data,setData] = useState(null); const updateState = jsonData => { setIsloading(false); setData(jsonData); }; useEffect(() =>

How to use fetch with async/await?

隐身守侯 提交于 2020-04-16 06:12:18
问题 I start by saying that I am not 100% sure this is the problem, I mean using await and async. This is the scenario: I run this when I first load the page, and works fine, I get the data : externalContent(url); function externalContent(url) { fetch(url) .then(res => res.json()) .then(data => { ...cool data... }); } But then I need to be able to click a button and re run that function with the fetch So I do $(".alm-filters--button").on("click", function() { externalContent(url); }); But when I

How to use fetch with async/await?

99封情书 提交于 2020-04-16 06:06:02
问题 I start by saying that I am not 100% sure this is the problem, I mean using await and async. This is the scenario: I run this when I first load the page, and works fine, I get the data : externalContent(url); function externalContent(url) { fetch(url) .then(res => res.json()) .then(data => { ...cool data... }); } But then I need to be able to click a button and re run that function with the fetch So I do $(".alm-filters--button").on("click", function() { externalContent(url); }); But when I