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
1 answer
28 views

Asynchronous recursive function for generating a unique Id

The code below is my first purpose built asynchronous recursive function. It took me a while to figure out how to write the thing, and I would like a second opinion. It's part of a project for The ...
user avatar
1 vote
0 answers
56 views

Processing buffer in javascript with graceful shutdown

My team has been doing some refactoring in an app and we needed to add a buffer to our data pipeline processing. We are working with node.js and javascript. Specifically, there is an event emitter ...
user avatar
  • 111
0 votes
1 answer
80 views

Reading and modify big set of data

I have a method that iterate over my table question in database and then will split a column commentaires and finnally put ...
user avatar
  • 143
0 votes
0 answers
24 views

Suggestions on the way I register a double tap (Unity mobile game)

So, in Unity, I wanted to trigger an event whenever the player double taps. Once the player has tapped the screen once, a countdown starts, and before time runs out the player must tap the screen ...
user avatar
2 votes
0 answers
126 views

What is better - using SerialPort with or without await/async methods?

I'm having an implementation using SerialPort in C# using Visual Studio 2019. I'm using it in a Windows Application, using .NET Framework 4.7.2. When I open and ...
user avatar
2 votes
2 answers
54 views

Concise handling of async tasks with timeouts in c#

Often I have async functions that I want to be able to time out, this timeout is independent of the greater scope of the application. However the function should also take into consideration the ...
user avatar
  • 45
2 votes
1 answer
106 views

Cleanup Async WhenAll

I have a sequence, retrieve data from a vendor API, cleanup our stage tables, and write the retrieve data into the database. What I have: ...
user avatar
  • 517
0 votes
0 answers
36 views

Async generator that processes input enumerable in batches-at-a-time

I have a lot of Input documents, which contain collections of sentences. I would like to use an online sentiment API to attach sentiments to each of these sentences ...
user avatar
3 votes
0 answers
74 views

Handling boilerplate tasks via service pipelines

Here's a small experiment about handling boilerplate tasks via service pipelines. It's similar to the HTML pipeline but simpler and multipurpose. I've updated the question and this is the 2nd version ...
user avatar
  • 43.8k
5 votes
1 answer
391 views

C# Async FileInfo Extensions (Copy, Move, Delete)

Here is my effort to implement extensions for FileInfo object: ...
user avatar
  • 151
1 vote
2 answers
73 views

Retrying a RestRequest

I wrote a method that lets me retry RestSharp requests when a specific exception is thrown. Here's the code for that method: ...
user avatar
0 votes
0 answers
116 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 ...
user avatar
  • 111
1 vote
1 answer
87 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 ...
user avatar
  • 277
3 votes
2 answers
381 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: ...
user avatar
1 vote
0 answers
52 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 ...
user avatar
1 vote
0 answers
50 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 ...
user avatar
  • 111
3 votes
1 answer
220 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 ...
user avatar
  • 131
0 votes
1 answer
236 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....
user avatar
  • 449
3 votes
0 answers
82 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 ...
user avatar
  • 31
3 votes
1 answer
68 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 ...
user avatar
11 votes
3 answers
490 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 ...
user avatar
  • 111
0 votes
1 answer
178 views

C# Asynchronous Lock class

I'm wrote Asynchronous Lock provider for reducing lock that breaks async keyword. All tasks with async and ...
user avatar
  • 95
0 votes
1 answer
1k 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: ...
user avatar
1 vote
0 answers
413 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 ...
user avatar
4 votes
1 answer
88 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 ...
user avatar
1 vote
2 answers
120 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 ...
user avatar
  • 777
3 votes
3 answers
407 views

Throttled execution of an enumeration of Tasks

Example of use: var users = await usernames.SelectTaskResults(GetUserDetails, 4); where GetUserDetails(string username) is a ...
user avatar
0 votes
0 answers
59 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 <...
user avatar
  • 95
3 votes
2 answers
123 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. ...
user avatar
0 votes
1 answer
462 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 ...
user avatar
  • 195
0 votes
0 answers
220 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: ...
user avatar
-1 votes
1 answer
125 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: ...
user avatar
0 votes
1 answer
160 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: ...
user avatar
1 vote
0 answers
114 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 ...
user avatar
1 vote
1 answer
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 ...
user avatar
3 votes
1 answer
319 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 ...
user avatar
  • 161
1 vote
0 answers
34 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 ...
user avatar
  • 625
4 votes
1 answer
76 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 ...
user avatar
  • 143
2 votes
1 answer
71 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. ...
user avatar
8 votes
3 answers
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 ...
user avatar
2 votes
1 answer
675 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 ...
user avatar
5 votes
1 answer
315 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 ...
user avatar
  • 51
4 votes
3 answers
208 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 ...
user avatar
2 votes
1 answer
202 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, ...
user avatar
3 votes
2 answers
407 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 ...
user avatar
  • 225
-1 votes
1 answer
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 ...
user avatar
3 votes
0 answers
45 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 ...
user avatar
5 votes
2 answers
1k 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 ...
user avatar
  • 161
2 votes
0 answers
130 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: ...
user avatar
  • 645
3 votes
0 answers
70 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. ...
user avatar
  • 31

1
2 3 4 5
7