Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
108 views

Simple priority task scheduler implementation

My project I am working on requires the following functionality for the processed messages: each message has a priority messages with higher priorities should have precedence over the ones with lower ...
Alexei's user avatar
  • 1,806
2 votes
1 answer
154 views

Proving that a Window Message is being sent by async/await

I asked a question on Stack Overflow and there's a discussion between @Serg, who posted an answer and @Jimi, whose comments suggest that the answer might be wrong. So I implemented the following code ...
Thomas Weller's user avatar
0 votes
0 answers
46 views

Synchronisation access to a shared class in Python server with async/await

Last week I wrote a simple server on FastApi to run ML model to classify a text on Chinese (split text on separate words). When I had clarified work of this model with API, it became time to confirm ...
Gleichmut's user avatar
  • 121
0 votes
0 answers
57 views

small app with bad practices on node.js and vue.js

Can someone help me to understand and give me code review of my small todos APP, why my code in backend is bad? Also give me a answers for some of my questions, please: Where my code is bad? Where do ...
Олег Лазорик's user avatar
4 votes
1 answer
159 views

Implement DRY principle with IAsyncDisposable

This is a tiny class that creates backup copies of a file so these can be diff'ed to spot the changes compared to last run; used when generating code and so far has proved to be very helpful. ...
aybe's user avatar
  • 612
1 vote
0 answers
163 views

Caching tasks and removing them from the cache when faulted [closed]

Is the code in Test1 and Test similar if it's being called like in RunAsync? The example is simplified, but this is an application with a high concurrency during ...
Dirk Boer's user avatar
  • 650
3 votes
2 answers
115 views

Idempotent JavaScript script loader

I wrote an idempotent script loader (for the browser), where the same script won't be loaded more than once. scriptLoader.js: ...
lonix's user avatar
  • 143
1 vote
0 answers
559 views

CoreBluetooth delegate to async stream

I want to use async/await by AsyncStream for Bluetooth scanning. The CoreBluetooth is using the delegate pattern. The following code provides an adapter for using ...
lotusirous's user avatar
2 votes
2 answers
2k views

Extension methods to modify an async Task's type from Task<IEnumerable<T>> to Task<List<T>>

I've written a lot of (await SomeTask).AsList(); in my project, and it's kind of annoying to keep wrapping it. To fix this I've written a little extension method on ...
Joost00719's user avatar
0 votes
1 answer
1k views

TCP Server using Tokio

Solving the following problem on Protohackers: https://protohackers.com/problem/1 The problem: Each request is a single line containing a JSON object, terminated by a newline character ('\n', or ...
Rish's user avatar
  • 2,341
1 vote
1 answer
129 views

Asynchronous tasks to subscribe to orders and fills

Pretty straightforward question. The methods SubscribeToOrdersAsync and SubscribeToFillsAsync are pretty similar due to ...
nop's user avatar
  • 729
2 votes
0 answers
160 views

Timer built in Unity using Async Await

For learning purposes, I built a timer that does something every x seconds in Unity using an async Task instead of a coroutine. I'd like to know if there is a less awkward way of writing this: What ...
willywinelover's user avatar
1 vote
0 answers
57 views

How to make memory and cpu efficient a code

I am using a python scraper code to grab publicly available data from http://103.48.16.132/echalan/ but it takes almost ~6gb of memory and more cpu. I need to run ...
Learner's user avatar
  • 111
2 votes
1 answer
108 views

Basic node login routes for authentication system

I am building a basic authentication system with a node backend and wonder whether I am using the try-catch block excessively. I have this example controller: ...
user8758206's user avatar
3 votes
0 answers
650 views

Async FIFO processing of database writes - naive implementation in .Net 6

One of the companies I was recently interviewing with gave me a following task to implement in a day or two using .Net, just to see where my coding abilities are at: Implement a Web API that gets ...
mi105's user avatar
  • 31
0 votes
1 answer
555 views

Deleting entities asynchronously in C#

I have a method that takes a collection of objects, and in turn calls a method that handles a single object. My question is, do I need to handle the tasks coming from the ...
Russ's user avatar
  • 133
1 vote
1 answer
3k views

Process a binary file by chunk using a read stream in nodejs

I want to process a file chunk by chunk to prevent memory exhaustion. I need to consume the file using a read stream. When trying it, this implementation seems to work fine. I am asking your expert ...
Louis Coulet's user avatar
0 votes
1 answer
355 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 ...
ablueblaze's user avatar
1 vote
0 answers
78 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 ...
Andrés's user avatar
  • 111
0 votes
1 answer
127 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 ...
Coder95's user avatar
  • 143
2 votes
0 answers
7k 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 ...
Hans Billiet's user avatar
3 votes
2 answers
4k 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 ...
Adriaan's user avatar
  • 55
2 votes
1 answer
263 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: ...
Greg's user avatar
  • 539
3 votes
0 answers
95 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 ...
t3chb0t's user avatar
  • 44.3k
5 votes
0 answers
3k views

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

Here is my effort to implement extensions for FileInfo object: ...
SeReGa's user avatar
  • 151
1 vote
2 answers
1k 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: ...
Erick Santander's user avatar
1 vote
1 answer
342 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 ...
Mike's user avatar
  • 277
3 votes
2 answers
548 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: ...
Hazel へいぜる's user avatar
1 vote
0 answers
148 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 ...
Sourav Kannantha B's user avatar
1 vote
0 answers
73 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 ...
allmhuran's user avatar
  • 111
3 votes
1 answer
561 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 ...
davidtgq's user avatar
  • 131
0 votes
1 answer
862 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....
Bob's user avatar
  • 459
3 votes
0 answers
92 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 ...
Ton's user avatar
  • 31
3 votes
1 answer
780 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 ...
CodenameCain's user avatar
11 votes
3 answers
703 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 ...
dougj's user avatar
  • 111
0 votes
1 answer
531 views

C# Asynchronous Lock class

I'm wrote Asynchronous Lock provider for reducing lock that breaks async keyword. All tasks with async and ...
jay k's user avatar
  • 85
1 vote
1 answer
5k 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: ...
FatalSleep's user avatar
2 votes
0 answers
1k 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 ...
Vikas Prasad's user avatar
4 votes
1 answer
232 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 ...
user183872's user avatar
1 vote
2 answers
548 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 ...
Redu's user avatar
  • 886
3 votes
3 answers
1k views

Throttled execution of an enumeration of Tasks

Example of use: var users = await usernames.SelectTaskResults(GetUserDetails, 4); where GetUserDetails(string username) is a ...
Paul Totzke's user avatar
3 votes
2 answers
778 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. ...
Louis Coulet's user avatar
0 votes
1 answer
1k 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 ...
anddt's user avatar
  • 195
1 vote
0 answers
548 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: ...
Charlie Chap's user avatar
-1 votes
1 answer
842 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: ...
Mr. Squirrel.Downy's user avatar
0 votes
1 answer
398 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: ...
Rahul Sharma's user avatar
1 vote
0 answers
174 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 ...
Dracula's user avatar
  • 111
1 vote
1 answer
62 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 ...
user3378165's user avatar
3 votes
1 answer
752 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 ...
Adam H's user avatar
  • 161
1 vote
0 answers
86 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 ...
Anakhand's user avatar
  • 655

1
2 3 4 5
7