Questions tagged [async-await]

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

0
votes
0answers
5 views

How to handle exceptions in async code with Caliburn.Micro

I have a Button in my View <Button Content="Search" cal:Message.Attach="SearchAsync"/> which calls a function, which raises an exception. I am trying to catch this exception in my Bootstrapper ...
-1
votes
0answers
24 views

Problem understanding why does this code hangs

When I execute the following program and I click on button1, the program hangs. private void Button1_Click(object sender, EventArgs e) { a(); } private void a() { Task<bool> x = b(); ...
0
votes
2answers
24 views

How to use readline in NodeJs on an event (wait stream close)

I'm creating a bot that when it receives a message begins to read a text file and responds to the message with the contents of the file. Unfortunately, I can't get out of this asynchronous hell and I ...
1
vote
1answer
23 views

Awaiting multiple levels of Futures?

I have a getter for a singleton instance of a SQFlite Database, like this: static Database _db; static Future<Database> get db async { if( _db == null ) _db = await ...
-2
votes
1answer
10 views

How can I use await instead of callback for this library [duplicate]

I am building a nodejs app that fetches clash of clans data using https://www.npmjs.com/package/clash-of-clans-api. It is however using .then() callback functionality and I would like to use async/...
2
votes
1answer
70 views

Cannot access properties of an object, but the object exists [duplicate]

I was trying to sort an array of user objects coming back from the database base on their age, but something really strange happened. The following code isn't working: async function getAllUsers(){ ...
0
votes
0answers
10 views

Discord.js foreach with a time delay / wait [duplicate]

I have this code: message.channel.guild.members.forEach(member => { setTimeout(function () { //Some bla }, 1000); }); I would like to execute something for each member. This works, ...
-2
votes
0answers
35 views

Windows forms, reflection and await

I have a Winforms app (.Net Core 3.0) that needs to use a binary assembly created for .Net Core 2.1 The binary assembly is loaded through reflection. Some objects are instantiated (also through ...
0
votes
1answer
23 views

Abort async function which contains setInterval with a eventcall

Firt of all: i do not master the async-await and promises syntax. So I'M very sorry if my snippet code is a piece of sh... I want to call a function (launchTestAtFrequency) which launch an interval ...
2
votes
3answers
36 views

Doing an async operation on each item while doing a “double iteration” on an array

Don't know if the terminology is correct, but I have an array of objects, which also has other arrays in it. I need to go through each of these items. If the operation wasn't async it would look ...
0
votes
2answers
30 views

Async-Await Still running asynchronously

Awaiting Select * function then doing stuff after its done printing. But its rushing right past the await doing everything after then printing the output. so its sort of going: calls Await function ...
-5
votes
0answers
48 views

What Task class is supposed to do for parallelization purposes, why it exists? [on hold]

Ok, I've already made this question Difference between Task.Wait or Task.Result and a normal method? and no one was able to answer. I'll try to be more polite this time. Can you please explain me in ...
-2
votes
1answer
52 views

What is the Most Ideal Way to Await a Set of Tasks?

I am exploring async/await and have found a curious scenario that I need guidance on resolving. For reference, the code seen in this question can be found here: https://github.com/Mike-EEE/Stash/...
0
votes
2answers
17 views

JavaScript async/await variable null [duplicate]

I am using promises and async to wait for a web request to finish. The variable info is empty when displaying its value using console.log(infos); I am unsure as to why and what I am doing wrong? var ...
0
votes
0answers
25 views

VB.Net Task result is automatically converted to Task(of Task)

I'm trying to convert a sub to be async and, according to every documentation (and as far as I can remember, I did it in the past), it says that I should convert my sub to a Function() as Task. My ...
-2
votes
2answers
97 views

Using await in same line as method call c#

Can calling await in the same line as the async method be slower than calling normal method? From what I know asynchronous methods are good for I/O operations like getting data from the database. But ...
0
votes
2answers
85 views

Async method not returning control back to caller method

I have the following code class Program { public async Task<bool> StartMyTask() { await Foo(); return true; } public async Task<bool> Foo() { ...
2
votes
1answer
90 views

What does determine the amount of time an “await” takes?

I have the following code to read bytes from a TCP stream (I've removed error checking): /// <summary>Awaitable. Reads a certain amount of bytes from a network stream. Returns false /// on ...
-1
votes
0answers
29 views

C# - What happens to async functions after request completes [duplicate]

Say for example I have an api. So what happens: The request comes in Some actions are taking place I have a log function that write what the user did to the database Request completes and an output ...
0
votes
3answers
100 views

Foreach async c#

Imagine I have a list of classes that have the same async method, I can foreach on the list to do : public async Task Test() { foreach (var runner in _runners) { await runner.Test(); ...
0
votes
0answers
30 views

What is the meaning of () in this code of JavaScript? [duplicate]

I am new learner of JavaScript. I saw the following code somewhere but can't understand why there is ( before async and () after that? I know arrow functions in JavaScript but it seems this is a ...
0
votes
2answers
61 views

C# how to use async and await?

I make serial communication method. it return receive message first, button click List<string> SendPkt = new List<string>(); List<string> RecvPkt = new List<string>(); ...
0
votes
2answers
24 views

Where to place async/await in this case?

I have looked through docs, read other questions and answers, but I still can't get my head wrapped around what function to make async, and where to place the await, to get the behaviour that I want. ...
4
votes
2answers
66 views

async Array.map() inside another map call

I have a method that receives a profiles array and I have to map for each profile and inside this map I have to map again in the photos propriety, which contains the pictures ids for requesting to an ...
0
votes
0answers
25 views

How to recursively query graphql with recompose before the component loads

I am using graphql and recompose. I am trying to build breadcrumbs by grabbing a singular item from graphql, place into an array, if there is a nest value within, make another call until the nested ...
1
vote
2answers
43 views

Why am I getting “UnhandledPromiseRejectionWarning”?

I am attempting to call an asynchronous method. The asynchronous method is: async connect() { this.pool = await mysql.createPool(this.conf); await this.pool.getConnection().catch((err)...
0
votes
1answer
43 views

Child functions and async await

In one of my API endpoints I fetch a json resource (1) from the web and edit it to fit my needs. In the "lowest" or "deepest" part of the tree I'm trying to fetch another resource and add it to the ...
-1
votes
2answers
48 views

Unsure how the value of type Guid is being converted to Task<Guid>

I've designed the following method to create records. public Task<Guid> NotAwaited() { Account account = new Account(); Context.Accounts.Add(account); Context.SaveChangesAsync(); return ...
0
votes
1answer
22 views

What is the best way to use async/await inside onAuthStateChanged() of Firebase?

I'm using Firebase authentication with async/await in React Native. I'm looking for a better way to await inside firebase function. So my question is What is the best way to use async/await inside ...
2
votes
2answers
21 views

React won't batch setState calls inside event handler if there's an await call before or between them

I've found this interesting React behavior that I would like to know more about. Usually React will batch multiple setState() calls when inside an event handler, right? But I tested that React won't ...
0
votes
1answer
25 views

How to test async void DelegateCommand method containing await with xUnit?

It is my first time when I write unit tests for async method. I am using xUnit. I searched SO with no promissing results. Best I found, but didnt work for me, is to implement IAsyncLifetime from THIS ...
0
votes
0answers
23 views

Visual Studio designer crashes when showing control with async await in Load event

I have a control named A with a (DevExpress) GridControl and I made the Load event async to get some initial data and provide them to GridView datasource. When i open the designer of parent control B ...
0
votes
1answer
23 views

Why am i getting [Object Promise], how to work with a promise

I am new to Vue.js and Axios. Working with a promise always confuses me. Can anyone guide me here. I am calling an API looking for an access_token. I want to store this token and use it in a ...
0
votes
2answers
29 views

async / await handling error in node js mongodb

I'm using async function in my node, here I'm calling multiple queries with mongodb (i.e) : let data1; let data2; try{ data1 = await mongoQuery1 }catch { res.send(error) } try{ ...
1
vote
1answer
46 views

How do I write async/synchyronous variants of one Python program?

It's normal to develop a simple implementation first. So, for example, we might start with a non-concurrent program, and then add concurrency. I'd like to be able to switch smoothly back and forth. ...
0
votes
0answers
42 views

How to thread safe and make a parallel tasks, parallelization and thread safe

I want to make my code optimize and also safe async thread in c#. The code I have currently which redundant enough to use twice Task.WhenAll, am planning to use only one and make sure the task is ...
0
votes
2answers
33 views

Can I use await without async function?

I want to declare variable that it receive result of asynchronous function var eff_histo= await _eff_histo(selectedline); the await expression can only be used in an asynchronous function
1
vote
1answer
26 views

Waiting for async function to return true or false - how do I check return value?

I have an async function songAlreadyInQueue that will return true if an ID is found in a database, false otherwise. I want to use the function like such: if(!songAlreadyInQueue(ref, id)){ // do ...
-2
votes
2answers
44 views

How return a value from an async/await function [duplicate]

I am trying to write a reusable function that doesn't return until it has resolved promise from a mongodb query. I can nearly achieve this using a IIFE function but seem unable to access the resolved ...
0
votes
1answer
33 views

How to test async/await API calls and update React state

I want to test an asynchronous click event in React that does two things: 1. Make an API call to send a POST request. 2. After the post request is successfully made, update the state in top level ...
0
votes
2answers
41 views

I wish to understand the behavior of promise inside and outside callback function

I'm fairly new to NodeJS and am trying to understand async, await, and promises. The likes variable is undefined if I take resolve() outside of the callback scope of 'con.query' (still inside the new ...
-1
votes
0answers
38 views

How to properly flowtype Promise.all() calls using callbacks

Live tryflow class A { name: string; constructor(name: string) { this.name = name; } } export const foo = (_in: A): Set<A> => { // Some logic is executed here to generate a new ...
-1
votes
3answers
73 views

Does calling .Result on a task that has already been awaited break the async pattern?

By the time the code calls Task.Result, it has already been awaited, so does the asynchronous pattern here still hold? class Program { static async Task Main(string[] args) { var ...
1
vote
2answers
109 views

How to call one of multiple functions - JavaScript?

I have three functions: Change Email Change password Change otherData And One Button to call them , when the user changes his data without change Email Or Password I don't wont to call other ...
0
votes
2answers
23 views

Angular 6 - Child (Inner) Component emit an EventEmitter and wait to Parent Component return a respond

I have this component as a Parent component (facility.component), and I embedded a child/inner component (editableTable.component) inside this parent component, something like this facility....
0
votes
0answers
7 views

Await error when loading mobilenet from tfjs

I am following this tutorial https://github.com/tensorflow/tfjs-models/tree/master/mobilenet When I try to load the module with: require('@tensorflow/tfjs-node') const mobilenet = require('@...
1
vote
3answers
56 views

How to convert Promise code to async await? [on hold]

I have a piece of code: db.dropDb() .then(() => { console.log('Success.'); }) .catch(err => { console.error(err); }); and it works as expected. However, I have ...
1
vote
1answer
29 views

Promise.all no return res map nodejs

We are integrating with Outlook api and we need to group the attachments in the recovered emails: We re trying this way: const result = await client .api('/me/messages') .filter(...
-1
votes
3answers
72 views

Correct way of returning a task in C#

I have a scenario wherein I need to return a method that can be awaited from the caller. I have here my implementations, and I just want to know which of which is the correct one. Method 1. public ...
0
votes
1answer
37 views

How to convert below code used for the database connection using EF 6 to async task in C#?

I am trying to create the async task for the already existing code in my project for the database connection using EF 6. I have created async task and it works fine, you can refer Using Async Task ...