Skip to main content

Questions tagged [async-await]

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

Filter by
Sorted by
Tagged with
2 votes
1 answer
139 views

Giving an alternative Async method to a service [closed]

I have an interface, implemented by a service, that I inject here and there in my codebase. I would like to give the opportunity to use either the normal method or its async equivalent. ...
Arthur Attout's user avatar
8 votes
3 answers
4k views

await user input with async/await syntax

for clarity: moved here from stackoverflow after being pointed to Code Review being the better place for this question I love async/await and Promises since I got my hands on them. And I might be ...
gaugau's user avatar
  • 191
2 votes
1 answer
2k views

Send message and wait for receive while using async/await and promises the proper way

I have this working code, but sendAndReceive function looks ugly/smelly to me. Eslint complains about using await inside a loop, and using ...
heltonbiker's user avatar
5 votes
1 answer
712 views

Parallel Calls to External WCF Service - ASP.NET Web Api

I have come across a situation where I feel running some code in parallel will greatly improve performance, but I am concerned about the implementation and am looking for some confirmation. Take the ...
ZMJ's user avatar
  • 51
4 votes
3 answers
307 views

Asynchronously assembling a complex object

Sanity check needed, as I'm still very unfamiliar with the nuances behind async/await and how they relate to more traditional Task / TPL code. I have a high-level repository layer which is assembling ...
Bryan Boettcher's user avatar
2 votes
1 answer
587 views

A method that calls multiple async tasks with error handling, done the right way?

I've got a method, CheckForValue(), that uses named pipes to send a message to another process running locally, and then receive a message from that process, ...
user3591541's user avatar
3 votes
2 answers
420 views

Improving Async/Await Javascript Code

I'm working on a data analytics dashboard in Node.js as a portfolio piece. I've built a pipeline that gets the data where it needs to be for more processing, however, I feel the below code can be ...
BBirdsell's user avatar
  • 235
-1 votes
1 answer
30 views

Am I using the same Typescript variable? [closed]

I am passing a in as a parameter and want to return b. This works, however I feel like it is wrong because I shouldn't have to ...
user10076130's user avatar
3 votes
0 answers
53 views

n executions of a periodic goroutine

I'm new to Go and have a use-case for periodically executing an async work-function. I want the interval between work-function executions to be constant (not the time between one finishing and the ...
geofflittle's user avatar
6 votes
2 answers
3k views

Simple async task scheduler

I've written a .NET Core console application to monitor the operation of a sensor network and I'd like a review of the task scheduling performed by the main program loop. There are three tasks that ...
PeterJ's user avatar
  • 171
2 votes
0 answers
268 views

Async linked list to and from async iterable

I'm working on some stuff that works better with (immutable async) linked lists such as this: ...
Juan's user avatar
  • 655
3 votes
0 answers
77 views

Which one should I choose for simple task: async/await or promise.then?

I made a helper function for drawing the map(OpenLayers). Then I made another helper function for fetch(axios.get) the map URL. ...
Ye Cai's user avatar
  • 31
2 votes
0 answers
86 views

I'm just starting out with tasks. I need to know if there's a better way to do TAP for socket handling (serving a request)

I've got this quick and dirty little console app in C# to serve an HTTP/HTML page. ...
honey the codewitch's user avatar
9 votes
1 answer
3k views

Reading one source Stream by multiple consumers asynchronously

The problem was using single Stream from the HTTP response in multiple consumers simultaneously. For example: while data is loading, I want write it to the some ...
aepot's user avatar
  • 2,019
1 vote
0 answers
70 views

ReadAsync: Continuously reads stream and spits out Packets and Fill incomplete Packets

I have difficulties when sometimes a game client sends a list of packet in the same buffer, where it is split before processing. The biggest problem is when any packets don't come complete. For ...
Johnny Camargo's user avatar
3 votes
1 answer
89 views

Update cache with minimal blocking

As part of the task, it is allowed to use slightly outdated data. It is required that only one thread per key is involved in the critical section, while the remaining threads use data from the cache ...
UserName's user avatar
  • 131
3 votes
1 answer
45 views

User Access Authorization for Web Resources

Im refactoring a large internal legacy application and part of the stuff I want to get rid is the widespread code repetition. I'm starting with the way the website checks if a User can access a ...
10110's user avatar
  • 171
4 votes
1 answer
654 views

Getting a Future from a Vector and a function

I'm pretty new to Rust and to it's async/await model, and I'm trying to do something that looks like a specialized Haskell's traverse function. Given a ...
Molochdaa's user avatar
  • 153
4 votes
0 answers
264 views

Chat using async Python and sockets

I am trying out websockets using the python async framework aiohttp. Basically I have created a game which will include multiple ...
doctorsherlock's user avatar
4 votes
1 answer
3k views

Wrapping an asynchronous generator in Python

Since Python 3.6 and PEP 525 one can use asynchronous generator: ...
Delgan's user avatar
  • 551
4 votes
1 answer
671 views

Running an async function synchronously

Sometimes I have the need to call an async function from a non-async function and get the result back synchronously. Therefore I wrote the following helper function to be able to do this in one line. ...
LittleEwok's user avatar
3 votes
0 answers
413 views

Mern stack app on error handling, async await, try-catch and avoiding DRY in controller functions

I'm looking for a review of my backend code on how to keep it more DRY. I see a lot of repetition in validation part of email and password, also I need some advice on if I have used the try-catch and ...
ubuntu7788's user avatar
1 vote
0 answers
48 views

Memoization of slow URL get requests

Purpose of this small module is to allow memoization of slow URL get requests. I intend to send many of these to download a bunch of files from internal (rather slow, old) website. Some requests may ...
biosckon's user avatar
  • 173
2 votes
0 answers
36 views

Web API wrapper design and sharing EF database context

I'm trying to keep my sanity while working with a legacy winforms application that uses an web api, both maintained by my team. In the past we have multiple cases of methods using wrong api endpoints,...
Rubens Farias's user avatar
1 vote
0 answers
51 views

Awaiting the completion of a server request

I faced the following problem. I have a Server object server which exposes TriggerStateChangeAsync() which return an ...
Ackdari's user avatar
  • 141
1 vote
0 answers
1k views

Execute command using `asyncio.create_subprocess_shell` and yield lines of stdout, stderr and finally the return code

My task is to run a subprocess using asyncio.create_subprocess_shell and yield the lines of output. I am using asyncio to avoid ...
user7610's user avatar
  • 569
3 votes
0 answers
82 views

Is my async websocket python code correct?

This is the first time I am posting here, so please go easy on me : ). I am also writing for the first time python code which uses async / ...
Newskooler's user avatar
1 vote
0 answers
365 views

create vscode tree item extesion

I use the following code to add tree item to vscode extension, Im getting the data and build the tree according to the entries I got, the code works. As I new to typescript I appreciate your feedback'...
Jenny M's user avatar
  • 281
0 votes
1 answer
59 views

Registering a user and login

I have these following controller functions for registering a user and login, in my app, and I want to make it more clean and maintainable. Probably by using ...
ubuntu7788's user avatar
3 votes
1 answer
6k views

Cancelling A Task Without Cancellation Token

Some Task methods don't take cancellation tokens. This is a problem because some long-running tasks may never finish and there is no way to send them a cancellation request. This seems a bit dodgy to ...
Christian Findlay's user avatar
2 votes
1 answer
208 views

Cross-thread label countdown

Short and sweet... I wrote a cross-thread method that displays the countdown [in seconds] of a delay on a label. I'm fairly confident it's far from optimal, so I'm in need of that glorious ...
Owen's user avatar
  • 1,494
14 votes
2 answers
44k views

Using async / await with dynamic import() for ES6 modules

I am experimenting with the best way to standardise my dynamic import() expressions when importing javascript modules. import() ...
Rounin's user avatar
  • 409
2 votes
0 answers
342 views

Extension method: Task<T>.CoalesceAwait

There has been ongoing concern about the question of awaiting a task that could possibly be null, as when using null-coalescing operators. Consider the following: ...
Kyle Delaney's user avatar
3 votes
0 answers
101 views

HTTP download function in Rust (async/await)

Why am I fighting the compiler? - Wrote this, which works, but I feel like I'm breaking every rule in the book: ...
A T's user avatar
  • 485
1 vote
1 answer
242 views

Refactoring try blocks with async/await

I have two functions which I would like to simplify. They have largely the same logic, but one is asynchronous and uses one await in a try block. I'd like to have the logic in one place, but could not ...
Felix's user avatar
  • 263
1 vote
0 answers
1k views

SelectAsync With Max Degree Of Parallelism

I have been looking for the best approach to creating an extension method that would give me the ability to select in a linq query using async/await with a max degree of parallelism. I'm aware that ...
TheRock's user avatar
  • 171
3 votes
2 answers
3k views

Adding a cancellation token to TcpListener.AcceptTcpClientAsync()

There is no facility in TcpListener (or for that matter Socket) to close a listening socket that is waiting for a connection without throwing an exception. After running up a test bench with 8 ...
Rowan Smith's user avatar
7 votes
1 answer
4k views

Python: Asyncio object-oriented style

I'm seeking a review of some code I've written for a small personal project. The project is not yet mature enough for any domain specific details to be of concern - but I'm happy to provide further ...
Adam Hodgson's user avatar
1 vote
0 answers
969 views

Handle aws lambda function containing multiple axios call

I have written an aws lambda function in NodeJS which has 2 async axios call. ...
Akhil Ghosh's user avatar
1 vote
1 answer
1k views

Am I wrapping synchronous code in ktor/Kotlin coroutine correctly?

I'm playing with ktor right now. If I understand this correctly, code in ktor's handlers need to be as asynchronous as possible. So I was trying to figure out how do you write synchronous (potentially ...
art-solopov's user avatar
6 votes
0 answers
597 views

TPL Dataflow - Timer Action Block

I'm new to TPL Dataflow and was looking for an action block to basically push an object on a timer - specifically to produce heartbeats on every interval. I was unable to find anything out of the box ...
TheRock's user avatar
  • 171
3 votes
0 answers
5k views

Hosted service for queuing and running tasks in parallel in ASP.NET Core

I am attempting to construct a background service for an IIS-hosted ASP.NET Core project that basically queues tasks and runs them, and I decided to go with the ...
Bryder's user avatar
  • 139
3 votes
2 answers
4k views

Cancel Long Running Query using Cancellation Token AND SqlCommand.Cancel()

I need to be able to cancel a long running query programmatically through our application. The code below will kick off a long running query and give control back to the main thread. At any ...
Chris Carter's user avatar
0 votes
1 answer
482 views

Mixing Async and Sync in same HTTP request ASP.NET Core C#

Is it bad practice to mix async and sync call in same ASP.NET core API call? For example, in following code method CropBlackBroderOfAnImageAsync is an async method....
aamir sajjad's user avatar
3 votes
2 answers
87 views

Cleaner Way to Structure Asynchronous Code

The purpose of the code is to allow the user to select directories that will be crawled recursively in order to find particular files or file types to analyze en masse. The thing to bear in mind is ...
oldboy's user avatar
  • 151
3 votes
0 answers
415 views

Python AsyncIO pipeline

I wrote a small snippet to implement asyncio Pipeline - object that connects together Layers, and lets them create and pass ...
Illia Ananich's user avatar
3 votes
1 answer
196 views

Token Bucket context manager for rate limiting async calls

I've written a class that implements something akin to the token bucket algorithm so that I may rate limit aysnc HTTP requests made from my application. The code works but I'm still not sure if it ...
Pocketsand's user avatar
2 votes
0 answers
42 views

Passing JSON files through an API - node async

I am writing a small program which reads some JSON files, passes the content to an API, then saves the response in some more JSON files. A pretty simple task, and the code works fine, but I have been ...
Carasel's user avatar
  • 129
4 votes
1 answer
366 views

Data encryption / decryption on Node.js

I've implemented my first data encryption / decryption methods on Node.js. Although it might look similar to hundreds of sample implementations available online, I'm curious to get a feedback. I'm ...
Mike's user avatar
  • 277
8 votes
1 answer
456 views

Operation logger

GitHub, NuGet This component traces execution in a logical order instead of chronological as everybody else :) For example, the following code: ...
Dmitry Nogin's user avatar
  • 6,131

1
2
3 4 5
7