Questions tagged [async-await]

This covers the asynchronous programming model supported by various programming languages, using the async and await keywords.

3
votes
2answers
19 views

In Express.js how can we make res.send to wait for data to be fetched from database

The method res.send() returns (empty) before the data is fetched from database (Mongodb) from the method Skills.find({ skillbranch: branches[i]._id }, function (err, skills) { How can we add await ...
-3
votes
3answers
57 views

Is await must be called when invoke an async method?

When we call async method, as long as we don't await the result, we can do something else before we await the result. Something like: var resultTask = GetResultAsync(); //Do something else var result ...
0
votes
1answer
8 views

Testing an Async function using Jest / Enzyme

Trying run a test case for the following: async getParents() { const { user, services, FirmId } = this.props; let types = await Models.getAccounts({ user, services, firmId: FirmId }); let temp = ...
-3
votes
0answers
52 views

C# error all code paths return a value in async and await

i have created the async class, this class contains some properties. public async Task<UserResponseModel> SearchUserByUserName(string username) { } In code, we are sending emailid to check if ...
1
vote
1answer
20 views

Nodejs await for multiple database calls

I'm trying to construct a response in which two database calls are required. Currently I'm having trouble with Node.js's async/await feature. Here's the calling class: router.get('/:id/mailings', ...
2
votes
2answers
25 views

Promise.all rollback successful promises' actions on failure

I am executing multiple promises with the following snippet: await Promise.all([promise1, promise2, promise3]); What I would like to achieve is to rollback the effects of the successful promises on ...
3
votes
3answers
55 views

Does a function need to be declared as asynchronous to return a promise?

I'm using a helper function (fetchGet) returning an asynchronous function that returns a promise (fetchWrapper). Does this helper function need to be declared as asynchronous to itself return a ...
-1
votes
1answer
18 views

Is a non-awaited Task processed simultaneously (parallel)?

Until now I used to await my Tasks before continuing processing. But now I plant to do something meaningful instead of awaiting A normal async method where you await before continuing would be like: ...
1
vote
1answer
68 views

Multiple tasks running same method

I have a grid with multiple SQL queries, which I want users to allow to execute when they double click on a row in the grid. I want a user to be able to run multiple queries at the same time. I ...
0
votes
1answer
33 views

How to use MS webchat with bing speech in IE

I'm using Web-chat for my chatbot v4.3 (webchat-es5) https://github.com/microsoft/BotFramework-WebChat As browser-speech is not supported in IE, I want to use bing speech/cognitive speech service ...
1
vote
0answers
23 views

Difference between Kotlin Coroutine ,Android Async Task and Async await

I went through the Kotlin Coroutine, i understood how it works but i have a confusion between kotlin couroutine & Android Async.execute & Async await, As Kotlin coroutine run in the background ...
0
votes
0answers
15 views

'describe' is skipped when using await

The second level describe gets skipped in the report on using await inside it. I have a test structure where I read files asynchronously in multiple levels in my test and use the data for validation. ...
-5
votes
0answers
36 views

TcpListener eventually stops accepting connections from GPS clients

I am working on a server app in C# using TcpListener which is supposed to listen for 1000s of GPS devices. The current code is working fine as it is connecting with multiple clients but the problem ...
2
votes
1answer
63 views

how to print array in javascript that has element pushed to it asynchronously?

I am working on an end-to-end UI test cases using the protractor for non-angular application. I have a bunch of LI tags inside UL tag that is rendered on a webpage. and I need to get the value of all ...
4
votes
1answer
69 views

Start async task now, await later

C# programmer trying to learn some Python. I am trying to run a CPU intensive calc while letting an IO bound async method quietly chug away in the background. In C#, I would typically set the ...
1
vote
1answer
28 views

What's the difference between returning void vs returning Future<void>?

Is there a difference between an async method that returns void, and one that returns Future<void>? It seems that both are valid in Dart: void main() async { await myVoid(); await ...
0
votes
1answer
45 views

Can't send async post request

I'm trying to await post request. I've found request-promise-native package to make await requests. It works for GET requests but doesn't work with the POST. The URL is working, the auth hash is ...
0
votes
1answer
34 views

Use async with NodeJs MySQL driver

I want to reform the function router.get('/', etc) to one that uses async and await. The res.send and connection.query are making the trouble I don't know how to handle them using async/await ...
0
votes
1answer
34 views

How to make an array map iteration synchronous?

My current implementation doesn't work because the console.log for "after" is executing before the .map iteration on querySnapshop.docs has finished. In my console I see "before", "after", and then "...
0
votes
0answers
16 views

Cannot get insertId on pool connection

This is my mysql configuration var sql = mysql.createPool({ connectionLimit: 10, host : 'localhost', user : 'root', password : '****', database : 'db_name', multipleStatements: ...
0
votes
0answers
11 views

Expected mock function to have been called -Async

Trying to create a test case for the following function. Not familiar with async and await, using Jest and Enzyme for React Js. Goal: test to pass properly And make sure the function is getting ...
-1
votes
0answers
40 views

Do while loop is not working as expected inside async await [duplicate]

I am working on a loopback project where i need to fetch documents from Model. I am getting the results from Model, but my requirement is we need to fetch first 5 document results. In the first ...
0
votes
1answer
23 views

Await not returning since Chromium update

Has anyone had that problem with the most recent versions of Chromium-based browsers? My app worked in previous versions, and it works on firefox. But now there's a failure due to one await call ...
1
vote
3answers
53 views

How can I wait for a method that doesn't return a Future?

I am building a screen in an app using an existing model class which I can't modify. The model has a method called refreshList() which fetches some data from an API, processes it, and finally it ...
0
votes
0answers
45 views

Async tasks returning no results

I have around 10-15 ecto queries which I want to run async in my API code. I am using Task.async and Task.yeild_many Following is the code for async task - def get_tasks() do task_1 = Task....
0
votes
1answer
14 views

Does MongoDB Stitch Functions support async/await definitions?

Asynchronous function definitions on MongoDB (Atlas) Stitch display warnings on the GUI editor. Including the example code provided on the reference for Triggers. The code found here can be was ...
0
votes
3answers
52 views

Javascript: how to run sequentially slow functions?

I am not an experienced Javascript programmer but I find it very difficult to execute 2 time-consuming functions in the row. I have spent some days on studying promises or async/await but not success ...
2
votes
2answers
95 views

.Net Core Async critical section if working on same entity

I need to be sure that a method accessed via a web API cannot be accessed by multiple call at the same time if it work on the same object with the same id I understand the use of SemaphoreSlim but a ...
0
votes
2answers
36 views

How to use single catch function for nested async await?

I have this code: on('connection', async(socket) => { try { const promises = members.map(async(member) => { try { const users = await User.find({}) const _promises = ...
0
votes
1answer
12 views

async await: write stream to file while interpreting it

My async method receives a Stream that CanSeek. The complete stream must be written to a file. About the first 1000 bytes of the stream must be interpreted to fetch some data from the stream. The ...
-2
votes
0answers
40 views

Python + JSON: duplicates code infinity times [on hold]

im making a level system in my discord bot, somewhat works.. when you type it puts ur ID, EXP and LEVEL in the users.json but then when you type multiple messages.. instead of having EXP go up it just ...
0
votes
1answer
29 views

Async Error handling Wrapper does not work

I am trying to write a wrapper for express callback function displayUsers() in this case, it would append error handling logic to avoid using try catch everywhere. The main issue is that fn() ...
1
vote
3answers
63 views

How do i set the response of a promise to a variable

I have an async function that returns a value async getUsername(env:string,skuName: string,token:string): Promise<any> { let value = await this.getDeviceName(env,skuName,token); ...
-3
votes
1answer
43 views

Task.Delay or Thread.Sleep to pause execution in a sync method

I want to pause a sync method. I know I can to use: // SAMPLE 01 Thread.Sleep(30 * 1000) but it has a disadvantage of blocking the current thread. The alternative // SAMPLE 02 await Task.Delay(30 * ...
0
votes
0answers
15 views

How to async return from aiohttp server handler?

I am running a http server to handle slack API calls which arrive at the events endpoint. The slack documentation suggests that the app (this server) needs to acknowledge the receipt of the request ...
0
votes
1answer
25 views

Google Cloud / Firebase Functions: await is only valid in async function

I've created this function: async function getRoomTempFromRoomId(roomId) { const querySnapshot = await db.collection("sensors").where("room", "==", roomId).where("type", "==", "temperature")....
0
votes
2answers
25 views

window.reload() after subscribe result using async/await

I need to reload the browser after finish the forEach loop of the functionality on my Observable. I am using Angular 7, I am doing a forEach iteration and I want to reload the brownser at the end of ...
-1
votes
1answer
73 views

C#: performance difference between “a function with multiple awaits on async functions” and “one await on a Task containing several sync functions”

For example, we have two snippets of code: public static async Task TestAsync() { await Task.Delay(5000); } Task.Run(async () => { for (int i = 0; i < 3; ++i) { ...
-1
votes
2answers
88 views

Using awaited [async tasks] in different levels of architecture C#

I've been struggling for about some days now on checking where to do await and where not to. I have a Repository class which fetches the data from database. using EntityFramework the code would be ...
1
vote
1answer
26 views

How can I make tx.executeSql() function sync with async/await?

How can I make tx.executeSql(SQL, [], (tx, results) be a sync function with sync/await? I want to do some like this: tx.executesql is async so my closeDB() (closeDatabase()) doesn't work because ...
1
vote
1answer
24 views

JS Promises: Relationship between .then syntax and async/await (Apollo client example)

Sorry for the bad question format, but I just don't know what's wrong here: I'm attaching a JWT token to an Apollo client (using apollo-boost), like this: const client = new ApolloClient({ uri: '...
-1
votes
2answers
75 views

Request is not async

public class RollingRequests { private const int DefaultNumSimultaneousRequests = 10; private readonly HttpClient _client; // Don't worry about disposing see https://stackoverflow....
1
vote
1answer
33 views

Waiting for forEach loop in aws lambda function

How can I wait for the forEach loop to finish before the return statement is executed in aws lambda? module.exports.shipments = async (event) => { const axios = require("axios"); let data =...
8
votes
2answers
145 views

Task.WhenAny with cancellation of the non completed tasks and timeout

In my app I am creating some concurrent web requests and I am satisfied when any one of them completes, so I am using the method Task.WhenAny: var urls = new string[] { "http://resolved-error.com"...
10
votes
2answers
218 views

Why doesn't an infinitely recursive async function cause stack overflow?

I was thinking what happens when an async function recursively calls itself infinitely. My thought was that it will not cause stack overflow. But I can't exactly point out why this is the case. const ...
-2
votes
1answer
40 views

Multiple Async Calls?

I am using async/await. I am wondering how do I do multiple async calls all in parallel? do I do async method(){ call1(); call2(); } as it seems at least from the debugger it is calling one ...
2
votes
2answers
58 views

Curious behavior of async/await

I know the proper way to use await is warring it up with async function. I found this below approach while surfing online. Initially, I thought it will not work. But when I run this in my chrome ...
3
votes
2answers
66 views

When will/won't Python suspend execution of a coroutine?

When I run it on cpython 3.6, the following program prints hello world a single time and then spins forever. As a side note, uncommenting the await asyncio.sleep(0) line causes it to print hello ...
0
votes
0answers
22 views

Problem with async function: tx.executeSql()

I have a problem with a async function: tx.executeSql(). I'm doing a for() but as tx.execute is async my var i doesn't work the way I expect. the var i when I do the query is always = 3 (the last ...
0
votes
1answer
43 views

Async named arrow fucntion Error 'Unexpected token'

I am learning React, using create-react-app. There was a situation that Google could not solve. Where am I wrong? How to fix it? I don’t understand why my code works on codepen.io. https://codepen.io/...

http://mssss.yulina-kosm.ru