async-await

How to use fetch with async/await?

时间秒杀一切 提交于 2020-04-16 06:06:00
问题 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 measure the execution time of an asynchronous function in nodejs?

孤人 提交于 2020-04-16 05:48:22
问题 I'm trying to get the execution/response time of an asynchronous function that executes inside a node-fetch operation, like the following async function getEditedData() { var a = await fetch(`https://api.example.com/resorce_example`); var b = await a.json(); // Some aditional treatment of the object obtained (b) console.log("End of the asynchronous function") } I Used the library perf_hooks like this, but the execution time shows before const hrtime = require ('perf_hooks').performance.now ;

How to measure the execution time of an asynchronous function in nodejs?

我们两清 提交于 2020-04-16 05:48:08
问题 I'm trying to get the execution/response time of an asynchronous function that executes inside a node-fetch operation, like the following async function getEditedData() { var a = await fetch(`https://api.example.com/resorce_example`); var b = await a.json(); // Some aditional treatment of the object obtained (b) console.log("End of the asynchronous function") } I Used the library perf_hooks like this, but the execution time shows before const hrtime = require ('perf_hooks').performance.now ;

useEffect React Hook rendering multiple times with async await (submit button)

…衆ロ難τιáo~ 提交于 2020-04-14 07:28:32
问题 I am trying to basically disable the submit button so my api calls only get triggered once/ someone can't click on submit again while the operation is already underway. I converted the runOnSubmit function to an async function and call it directly. I have based this off many other solutions and basically when I do this and debug I can tell that isSubmitting is still set to true and the hook gets called multiple times/ the submitAsync function is called twice. Basically, the setSubmitting gets

async/await and the visitor pattern [closed]

孤街浪徒 提交于 2020-04-13 07:04:12
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 days ago . We've recently transformed one of our visitors for an object tree-like structure (that is about 40 levels deep) to the async/await pattern because the innermost accept methods now perform work which uses async/await. Everything works fine except when an exception is thrown deep in the call graph, then we run into

Nested Async Await Does not Wait

随声附和 提交于 2020-04-13 05:43:11
问题 I think I missunderstanding the behaviour of async await in c#. I have two methods that return a Task defined like public async Task Name() { await AsyncOperation() } Imagine AsyncOperation() like an PostAsync of HttpClient . Now I call them inside some other methods public asyn Task Method() { await Name1(() => { "bla bla"}); await Name2(); Console.WriteLine("Continue"); } This works as expected to me. Waits until Name1() and Name2() finish and then continues. Now I need to nest Name1() and

Pushing to an array in async function not working [duplicate]

百般思念 提交于 2020-04-11 16:27:27
问题 This question already has answers here : Best way to call an async function within map? (6 answers) Closed last year . Here is my code: exports.propertyById = async (req, res) => { try { const {propertyId} = _.get(req, 'params'), propertyData = await bService.getPropertyById(propertyId); console.log(propertyData); const propertyPhotoList = []; async function getPhotoData(item, index){ const id = item.split('#')[1]; const response = await fetch(`http://localhost:4000/api/propertyphoto/${id}`);

Pushing to an array in async function not working [duplicate]

吃可爱长大的小学妹 提交于 2020-04-11 16:23:28
问题 This question already has answers here : Best way to call an async function within map? (6 answers) Closed last year . Here is my code: exports.propertyById = async (req, res) => { try { const {propertyId} = _.get(req, 'params'), propertyData = await bService.getPropertyById(propertyId); console.log(propertyData); const propertyPhotoList = []; async function getPhotoData(item, index){ const id = item.split('#')[1]; const response = await fetch(`http://localhost:4000/api/propertyphoto/${id}`);

Exception thrown from task is swallowed if thrown after 'await'

送分小仙女□ 提交于 2020-04-11 02:06:09
问题 I'm writing a background service using .net's HostBuilder. I have class called MyService that implements BackgroundService ExecuteAsync method and i encountered some weird behavior there. Inside the method i await a certain task and any exception thrown after the await is swallowed but an exception that is thrown before the await terminates the process. I looked online in all sorts of forums (stack overflow, msdn, medium) but I could not find an explanation for this behavior. public class

Async Await Recursion in .NET 4.8 causes StackoverflowException (not in .Net Core 3.1!)

蓝咒 提交于 2020-04-10 14:48:32
问题 Why does the following code cause a StackOverflowException in .Net4.8 with only a 17-depth recursion? However this does not happen in NetCore 3.1 (I can set the count to 10_000 and it still works) class Program { static async Task Main(string[] args) { try { await TestAsync(17); } catch(Exception e) { Console.WriteLine("Exception caught: " + e); } } static async Task TestAsync(int count) { await Task.Run(() => { if (count <= 0) throw new Exception("ex"); }); Console.WriteLine(count); await