Questions tagged [async-await]

-1

votes
0

answer
23

Views

run await functions one after one

There are a lot of samples on running Async/Await functions. But only with one await call. I don't find a right sample that I can run await functions one after one async function a() { console.log('this is function a'); // do something } async function b() { console.log('this is function b');...
Bill
0

votes
1

answer
46

Views

Limiting concurrent async tasks

I want to upload potentially large batches (possibly 100s) of files to FTP, using the SSH.NET library and the Renci.SshNet.Async extensions. I need to limit the number of concurrent uploads to five, or whatever number I discover the FTP can handle. This is my code before any limiting: using (var sf...
CarenRose
1

votes
1

answer
368

Views

Task.WhenAll have finished BEFORE the Tasks it contains were finished

for (int i = 1; i < servers.Count;i++){ var server = new SpeedTestServer(servers[i]); server.dist = haversine(server); if (closestKnownServer.dist - server.dist > distTreshold){ closestKnownServer = server; this.servers.Add(server); this.servers.RemoveAt(0); } else if (Math.Abs(closestKnownServer.di...
KOLANICH
0

votes
0

answer
4

Views

An AsyncDuplicateLock that can be locked on all keys

I need a lock similar to the one from this answer from Stephen Cleary: https://stackoverflow.com/a/31194647/4381408 However, I also need to be able to lock on all keys at the same time. I'm using Stephen Cleary's AsyncEx library as well, so I thought of combining the AsyncDuplicateLock with an Async...
t.baart
1

votes
1

answer
1k

Views

Comparence of task.Status == RanToCompletion and task.IsCompleted

Consider this: readonly INotifyTaskCompletion _modelAsync; public INotifyTaskCompletion ModelAsync { get { return _modelAsync; } } public ctor() // pseudo code { _modelAsync = NotifyTaskCompletion.Create(GetModelAsync()); _modelAsync.PropertyChanged += modelAsync_Ready; } async Task GetModelAsync()...
Gerard
1

votes
3

answer
37

Views

Using Async/Await on multiple settimeout

To understand async/await, I am trying to display a console message once settimeout runs and expires. How do I fix my code below? I have 5 settimeout function and each should display respective message once finished. function t1(){ setTimeout(() => { console.log('1') }, 1000); } function t2(){...
vegabond
0

votes
1

answer
24

Views

Async/Await Axios returns promise and not data? [duplicate]

This question already has an answer here: How do I return the response from an asynchronous call? 33 answers export const isLoginValid = async token => { try { let result = await axios.post(API_URL + '/verify', null, { headers: { Authorization: 'Bearer ' + token } }); return await result.data; } ca...
user1986245
1

votes
1

answer
1.7k

Views

C# how to add Await to this function - SendEmailAsync - MailKit in Dot Net Core

I have code based on MailKit. Where do I add the await keyword? public async Task SendEmailAsync(string email, string subject, string mess) { var message = new MimeMessage(); message.From.Add(new MailboxAddress('Joey Tribbiani', '[email protected]')); message.To.Add(new MailboxAddress('Mrs. Chanandle...
Arun Prasad E S
1

votes
1

answer
384

Views

JavaScript await by default instead of manually

Async/await are really handy, but I want the opposite of their behavior. Instead of other functions continuing on unless I manually ask them to await a promise, I want functions to yield unless I manually specify that they continue running in parallel. For instance, this code would print out 1 3 2:...
Drew
1

votes
3

answer
18

Views

How do I structure tests for asynchronous functions?

I'm accustomed to writing Mocha tests using the standard NodeJs assert library like this: describe('Some module', () => { var result = someCall(); it('Should ', () => { assert.ok(...); }); }) but now my call returns a promise... so I want to write: describe('Some module', async () => { var result =...
ekkis
0

votes
0

answer
9

Views

Async data blinking right on refresh, but going away to screwing up then

With local data all works fine, but when I getting my async data, it's starts behaving very strange — when I refresh the page it's showing the right data for a half a sec, but then changes to some random values... I tried both way of getting async data — all the same. I am using coffeescript, so...
Oleg
0

votes
1

answer
25

Views

Using Async/Await with Azure App Services Web API

I have a .Net Web Api hosted as Azure App Service. (I have to call this from ADF as a web activity.) This API has some code which runs for a long time so I want to make this Async. This is how I am testing: [Route('apiA/[controller]')] [ApiController] public class AsynccallController : ControllerBa...
Gadam
1

votes
3

answer
126

Views

Async function missing a return statement?

I just finished writing the following method for a bug I'm working and was wondering why the compiler did not complain about the following function having the possibility of not returning? If I instead write if (false) the compiler immediately complains about not all paths returning a value. What ha...
User 5842
1

votes
2

answer
349

Views

Javascript async function is waiting for response without await

I am new to the concept of JavaScript's asynchronous behavior. The below code is confusing me. According to my concept function b should return before the wait function finishes executing because I am not telling it wait using 'await'. But the output I am getting is this : before then it waits for...
Ani
0

votes
3

answer
44

Views

Retry async/await try and catch block three times before responding with an error

Found similar issues, but none of which answered my question. I need to try to run an async function three times before throwing an error. Currently doing it with a while loop doing, which doesn't feel right to begin with. It is all happening in an express route. This is what my code currently looks...
theJuls
1

votes
2

answer
83

Views

Call a sync function asynchronously for UI responsiveness

I have a sync method GetReports() which return value will be used to set the data source of a UI control. It may take a while to run. Is it idiomatic way to call it asynchronously as the following? var l = new List(); await Task.Run(() => l = GetReports().ToList()); UIControl.DataSource = l;
ca9163d9
1

votes
4

answer
70

Views

Using Async/Await to call Async functions to assign values to keys in objects [duplicate]

This question already has an answer here: How to use Promise.all with an object as input 8 answers I am wondering how to assign values to multiple different keys asynchronously with Await/Async. Initially I had imagined merely calling the Async function would assign the values such as below: const...
Saga
1

votes
1

answer
80

Views

await is not a reserved word

Here is my code, exports.prepareMeshTerms = function(req,res) { var input = req.body, start = input.start, limit = input.limit, count = 0, pipeData = ''; MeshTerms.find().skip(start).limit(limit).exec(function (err, data) { if(err) { throw err; } if (data) { (async function(){ data.map(element => {...
user11170425
1

votes
1

answer
70

Views

Async/Await result is empty after await execution

I have a simple function: var result = ''; var url = 'http://someurl.com/?action=perform-action'; (async function() { let a = await fetch(url) result = await a.text(); })() console.log(result) I'm trying to put the result into variable but it returns nothing. My function simply checks if an email en...
Benzine
1

votes
2

answer
73

Views

C# async Task - Unit testing

I am new to C# unit testing and have to test if the method is working properly. Here is what I have so far: public async Task Post(API_FIRM_LINK aPI_FIRM_LINK) { db.API_FIRM_LINK.Add(aPI_FIRM_LINK); await db.SaveChangesAsync(); return Created(aPI_FIRM_LINK); } test method: Not really sure if I am on...
usertestREACT
1

votes
1

answer
28

Views

Abort previous running async componentDidMount

We have a component, connected to the redux store, that has this componentDidMount definition: async componentDidMount() { const page = await fetchPage(this.props.page); const section = await fetchSection(this.props.section); this.props.saveDataToStore({ page, section }); } So, every time the compon...
Emi
0

votes
1

answer
12

Views

Async await its showing undefined

export default class Search { constructor(query){ this.query = query; } async getResults() { const API_KEY = '1d4e862be156056d16d3390378173c21'; await fetch(`https://www.food2fork.com/api/search?key=${API_KEY}&q=${this.query}`) .then(res => res.json()) .then(data => { const result = data.recipes; co...
Wilker
0

votes
0

answer
11

Views

Alexa skill async await fetching data from DynamoDB

The following code is my launch handler in my Alexa skill and I have a variable named x inside of my handler. I am trying to set x to data that I'm getting from dynamoDB and to use it outside of the get function (I got the function from https://docs.aws.amazon.com/amazondynamodb/latest/developerguid...
user10796158
1

votes
2

answer
156

Views

async API call inside forEach loop

I ran into a problem that I cannot seem to solve, I'm guessing I'm missing some points in terms of async behaviour. The task is relatively simple: A wallet with money in different currencies needs to be transformed into a single currency. I want to get the exchange rate from following API: https://...
Manuel Hong
1

votes
2

answer
301

Views

Python - How to - Big Query asynchronous tasks

This may be a dummy question but I cannot seem to be able to run python google-clood-bigquery asynchronously. My goal is to run multiple query concurrently and wait for all to finish in an 'asyncio.wait()' query gatherer. I'm using asyncio.create_tast() to launch the queries. The problem is that eac...
Antoine Dussarps
-1

votes
3

answer
54

Views

How to call an async function in .NET without waiting for it

I have an async function in C# as follows: private static async Task AddEmoji(string emoji) { ... } I have a situation where I'd like to call it but I don't want to wait for its result and I don't care if it works or not. What's the right way to go about this? I thought I could just call it without...
Chris Rae
1

votes
2

answer
747

Views

JQueryPromise to Promise - how to convert?

I have a piece of code that returns a JQuery promise: const jqProm = server.downloadAsync(); I wish to use it inside async function. I was hoping I could create something like C# TaskCompletionSource, return dummy Task (Promise) and as a handler for jqProm resolve/reject set the status of dummy Tas...
user3284063
1

votes
1

answer
48

Views

Task.Wait() on async method works locally, but not via another method

I recently resolved a problem I had while trying to execute an async method. To me, this posed more questions than it solved. In short, I am happy that it works, but I don't know why it does. I was attempting to run the following method of the Microsoft Graph Client library: _graphServiceClient.User...
Johan Wintgens
1

votes
3

answer
1.2k

Views

Convert async await in while loop to promises

I can't figure out how to convert async await functionality in a while loop to a promise based implementation. repl showing the async await version https://repl.it/repls/IdealisticPepperyCoding var dependency = false; function checkDependency() { return new Promise(resolve => { setTimeout(() => {...
Zack Lucky
1

votes
1

answer
830

Views

Node await Promise.all() to be fully resolved

I'm working with promises and I need to know the result of all the items processed by an async method. So I thought that a Promise.all() would solve my problem like this: const values = await Promise.all(items.map((item) => { asyncMethodThatLogsAndReturnsBoolean(item); })); console.log(values); What...
Belen
1

votes
1

answer
819

Views

react native Async Storage not working

I'm trying to make an auth process so my App.js: import React, { Component } from 'react'; import { AsyncStorage } from 'react-native'; import Router from './Router'; import ScanForm from './components/ScanForm'; console.disableYellowBox = true; class App extends Component { state = { isLoggedIn: fa...
MohamadKh75
1

votes
2

answer
66

Views

How do I hide Task of Task?

Consider the following method: private async Task SendAsync(string data) { this.Tcs = new TaskCompletionSource(); await this.Stream.WriteAsync(...); await this.Stream.FlushAsync(); return this.Tcs.Task; } I have an async method, which I expect to return Task. But since I want to return TaskCompletio...
Gigi
1

votes
1

answer
538

Views

UnitOfWork with Entity Framework is not committing the transaction

I have an UoW class that has start and commit as below public class uow { private IDBcontext mydbcontext; TransactionScope trans = null; public uow(IDBConext mydbcontext) { this.mydbcontext = mydbcontext; } public void starttran() { if (trans == null) trans = new TransactionScope(TransactionScopeAsy...
jdoe
1

votes
1

answer
653

Views

Execute backend email process without making user to wait for it to complete

In my MVC application, I am having a functionality of sending message to the respective owners/dealers, by clients. The message model is as below: public class Messages { public string MessageFrom { get; set; } public string MessageUserEmailID { get; set; } public string MessageUserContactNum { get;...
Guruprasad Rao
1

votes
2

answer
1.1k

Views

How does the C# “event loop” compare to the JavaScript “event loop”?

The point at which I understood the JavaScript event loop was when I heard it described as 'When there is nothing to do, check the queue. But only check the queue when there's nothing left to do.' in the video https://www.youtube.com/watch?v=vMfg0xGjcOI. For example, if the totality of my JS progra...
user5648283
1

votes
1

answer
63

Views

Using async void method to run long-living operation

Is it appropriate to use async void method to start some long-living operation? I know Nito or Task.Run() could be used to Run Task from non-async method. What is the difference? Are there any pitfalls? By all that I mean, can I write like that: async void bar() { try { //... } catch (Exception ex)...
ilivit
0

votes
1

answer
22

Views

async function with await fetch inside do-while loop

I have a problem with the function below. I can see the log messages as follows: in fetchData before while in while After this, nothing happens until I get a timeout: VM344:1 GET http://192.168.1.91:27080/sds/deception/_find?batch_size=100&criteria={%20%22$and%22%20:%20[{%20%22$or%22%20:%20[{%20%22r...
RR1
1

votes
1

answer
580

Views

WebClient progress reporting using TAP

I'm wondering if there is a way to report WebClient progress without using EAP(Event-based Asynchronous Pattern). Old way(using EAP) would be: var client = new WebClient(); client.DownloadProgressChanged += (s,e) => { //progress reporting } client.DownloadFileCompleted += (s,e) => { Console.Write('d...
monoh_
1

votes
1

answer
871

Views

Using PushStreamContent to upload from an HTTPClient

I would like to upload a large amount of data to a web server from a client machine. I jumped right to PushStreamContent so I could write directly to the stream, as the results vary in size and can be rather large. The flow is as follows: User runs query > Reader Ready Event Fires > Begin Upload Onc...
Matt
1

votes
1

answer
625

Views

Do I need Microsoft.Bcl.Async package in .NET 4.5?

I have a project P which is targeting .NET Framework 4.5 and it has a NuGet package A which is targeted for 4.0 (it has no 4.5). Now, A has a dependency to Microsoft.Bcl.Async NuGet package. Is it safe to force-remove the dependency to Microsoft.Bcl.Async for the project P since it is targeting 4.5?...
ceco

View additional questions