As of May 31, 2023, we have updated our Code of Conduct.

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
0 answers
42 views

UIImageView loading from URL with cancellable task and safe to use in a UICollectionView

I am trying to make a UIImageView class / extension that can load an image from a URL. the image view should not get confused with concurrency when scrolling through a UICollectionView and the data ...
Halpo's user avatar
  • 101
4 votes
1 answer
120 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
  • 582
1 vote
0 answers
47 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
86 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
  • 131
1 vote
0 answers
217 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
489 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
638 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
  • 1,691
1 vote
1 answer
113 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
  • 699
2 votes
0 answers
66 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
50 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 ...
SIslam's user avatar
  • 111
2 votes
1 answer
77 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
355 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
174 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
1k 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
192 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
71 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
89 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
3k 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
2 votes
2 answers
1k 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
  • 45
2 votes
1 answer
234 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
  • 517
3 votes
0 answers
85 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
  • 44k
5 votes
0 answers
2k 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
557 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
243 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
496 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
120 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
66 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
387 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
505 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
90 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
311 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
629 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
414 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
  • 95
1 vote
1 answer
3k 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
1 vote
0 answers
834 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
177 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
220 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
  • 856
3 votes
3 answers
869 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
0 votes
0 answers
63 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 <...
jay k's user avatar
  • 95
3 votes
2 answers
363 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
458 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
445 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
272 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
162 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 ...
Parth's user avatar
  • 111
1 vote
1 answer
58 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
530 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
66 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
  • 645
4 votes
1 answer
118 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 ...
Josh's user avatar
  • 143
2 votes
1 answer
125 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

1
2 3 4 5
8