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
0
votes
0answers
23 views

Rust infinite loop in Tokio tasks join_all() made concurrency?

(From stackoverflow.com, they suggest me to post this question here) I'm trying to build a bot to check with accounts the status of a service connected to each of ...
0
votes
0answers
18 views

Async action on each items from a stream [closed]

I want to apply an async function to items retrieved through a stream. I have found two ways of doing it: Code 1 ...
1
vote
1answer
42 views

Regarding "Local variables should not be declared and then immediately returned or thrown" [closed]

Given the code: async getData() { const response = await handleRequest(…); return response; } Many of static code analyzers mark this code with an issue ...
3
votes
2answers
355 views

Asynchronous and recursive word square generator in C#

Overview I've created an asynchronous and recursive method of generating word squares, of any size (known as the order of the square), from a known word list. If you're unfamiliar with word squares: ...
1
vote
0answers
31 views

Event handling with async await in Python

Recently, I had to write a code to classify and rename lots of image files based on their content. So, I wrote a Python script which displays all those images as a slideshow to the me, and I can ...
1
vote
0answers
48 views

"streaming" messages to a broker from a batch-like source (eg sql database), optionally acknowledge back to the source

I am writing library code to help other developers send messages to a pub-sub event broker. In many cases, the message source will not be "stream-like". Specifically, most messages are ...
1
vote
1answer
78 views

Adding websocket functionality to send live data from a Python script. Any edge-cases or unexpected consequences to beware of?

The original purpose of this script was saving data to a local file, which is still the primary purpose. Since I may only obtain one copy of a data stream (not this particular Coinbase one; it's just ...
0
votes
1answer
107 views

An async time-based rate-limiting semaphore for C#

This is a class that allows only limited number of requests to proceed per period of time. This is designed for use with external APIs that require such rate limiting, e.g. 600 requests per 10 minutes....
2
votes
0answers
74 views

Fetch in JavaScript, but less messy?

I'm trying to separate the fetch logic from the component, but, due to the nature of async/await functions I have to write an async function to call other async function and I wanted to know if that's ...
3
votes
1answer
63 views

Posts data to endpoint, trying not to use .Result on async methods

I have a Send method that is working but want to refactor a portion where it is using PostAsync().Result and ReadAsStringAsync().Result. I've never written async methods before and don't feel I ...
11
votes
3answers
452 views

Asynchronously scrape fabric information

This is my first asyncio/aiohttp web scraper. I am trying to wrap my head around Python's asyncio/aiohttp libs these days and I am not sure if I fully understand it or not yet. So I'd like have some ...
0
votes
1answer
90 views

C# Asynchronous Lock class

I'm wrote Asynchronous Lock provider for reducing lock that breaks async keyword. All tasks with async and ...
0
votes
1answer
413 views

Asynchronous Event Handler

This class acts as an asynchronous event handler that will execute all attached tasks in an async/await context. Requires Nuget Immutables. Example usage: ...
1
vote
0answers
226 views

Are nested calls to `asyncio.gather()` dangerous?

I wrote this ~100 line script recently, where I tried out Python's asyncio library. When it comes to asynchronous programming in Python, I just have 2 days of ...
4
votes
1answer
73 views

ForEachAsyncSemaphore asynchronously processing tasks but enable fast fail

I know this has been done many times before, but this is my existing code taken from a sample I found to async process a list of tasks. I've seen Task.Run in use before in many examples, but I'm ...
1
vote
2answers
106 views

Racing promises and consuming them in the order of their resolution time

The ideas are When multiple async calls are made, to be able to start consuming from the first resolving one regardless in what order the promises are fired. To construct a modern emitter of async ...
3
votes
3answers
251 views

Throttled execution of an enumeration of Tasks

Example of use: var users = await usernames.SelectTaskResults(GetUserDetails, 4); where GetUserDetails(string username) is a ...
0
votes
0answers
58 views

Idea for writing asynchronous data processing chains easier (similar to `ReactiveX`) and its implementation

I'm writing my own library, that is for asynchronous network communication. and then, wanna write my own HTTP proxy server for load-balancing connections to backend servers with it. when I'm using <...
3
votes
2answers
101 views

Simple retrier of async function

I wrote a simple function for retrying the passed function in case it throws. I did it for my app that needs to call an external API through the network, which may spuriously fail. ...
0
votes
1answer
220 views

Using asyncio and aiohttp in classes

To better familiarize with async requests I wrote a very simple scraper that relies on aiohttp to retrieve some basic information from the product page (product ...
0
votes
0answers
119 views

Fastapi with Aiohttp not providing expected results

I am new to asynchronous programming in python. Below are two scripts(which perform the same operation) one in Fastapi + aiohttp while other is basic Flask + requests library: ...
-1
votes
1answer
82 views

c# make synchronization function waitable and cancelable [closed]

I need to call some synchronization function and need they running in background and canbe canceled. So I write this: ...
0
votes
1answer
129 views

Is this correct way to setup DB Infrastructure with repository pattern and Dapper

So, I am using Repository pattern with Dapper and ADO.NET. I have my based DB infrastructure setup as follows: ...
0
votes
0answers
93 views

Advice converting an onCreate firebase cloud function trigger with FCM Messaging to support async/await and database reads

I initially had a simple firebase cloud function that sent out a push notification to a topic when a new message child was created in my real-time database. But I wanted to add message filtering where ...
1
vote
1answer
57 views

Get images for PDFs from URLs

I Have the below code that gets urls of PDF files, send them to a convert function and returns them as images, is there a way to make this code more readable? Is there a way to avoid functions ...
1
vote
1answer
219 views

How can I speed up the processing of the received channel socket

This currently runs with 1400+ sockets and manages data correctly and in the manner the application requires. I do have an issue with the HandleData method where ...
1
vote
0answers
30 views

Stoppable asyncio thread class

A threading.Thread subclass intended for running an asyncio loop that has the ability to be stopped gracefully from another ...
0
votes
0answers
278 views

Angular Typescript Async queue service

i've implemented a waiter service in Angular for syncronice multiple calls to one async function and i want to know if there exists a simplier way of atchiving the same result or if it's over ...
4
votes
1answer
66 views

Catching Errors in Factory Method with express.js

My express.js application uses a lot of promises for interacting with a variety of services. Instead of including try/catch with each one, I've setup a fail safe factory method for all my express ...
2
votes
1answer
68 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. ...
6
votes
3answers
2k 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 ...
2
votes
1answer
469 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 ...
5
votes
1answer
243 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 ...
4
votes
3answers
178 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 ...
2
votes
1answer
133 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, ...
3
votes
2answers
396 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 ...
-1
votes
1answer
29 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 ...
3
votes
0answers
39 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 ...
5
votes
2answers
900 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 ...
2
votes
0answers
94 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: ...
2
votes
0answers
64 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. ...
2
votes
0answers
70 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. ...
8
votes
1answer
592 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 ...
1
vote
0answers
54 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 ...
3
votes
1answer
71 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 ...
3
votes
1answer
40 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 ...
4
votes
1answer
321 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 ...
4
votes
0answers
112 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 ...
4
votes
1answer
661 views

Wrapping an asynchronous generator in Python

Since Python 3.6 and PEP 525 one can use asynchronous generator: ...
3
votes
1answer
160 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. ...

1
2 3 4 5
7