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
5
votes
1answer
105 views

Scheduling using System.IObservable 2.0

As a follow up to this first attempt to create and use my own IObservable<T> implementation, this is version 2.0. The goal has been to correct the code where ...
5
votes
2answers
1k views

ForEachAsync extension method (a way to run an async operation on each item of a sequence in parallel)

In a recent project I worked on we faced some issues due to an excess of parallelization (thousands of threads were created and the overall result was a degradation of performance and several spikes ...
5
votes
1answer
11k views

Basic TCP server application in C# using async / await [closed]

I'm trying to get started with network and parallel programming in C#. I'm almost a complete novice in programming, so I'm looking for feedback on a small script I'm writing. The goal of the ...
5
votes
2answers
142 views

Async concurrency prevention class

Because I'm quite naive regarding C#'s Task Asynchronous Programming and concurrency in general, and because it's so difficult to test, I'm concerned about the safety of this code. It's likely that ...
5
votes
1answer
1k views

Asynchronous dictionary in Python

So I am working on writing a discord bot with discord.py. I decided, rather than making a serie of if/elif, to map the messages to the functions in a dictionnary, like so: ...
5
votes
1answer
2k views

Process List asynchronously with SemaphoreSlim for throttling extension method

I've got some methods that follow a similar pattern, and wanted to abstract some of the logic away into an extension method. Specifically, I am processing lists of objects with the TPL, and throttling ...
5
votes
1answer
373 views

Async access to School

I have this class with two public async methods, which also calls some private methods that are async. Here's the class: ...
5
votes
1answer
2k views

Implementation Async/Await

I have a simple ASP.NET Web API project. Now I want to make all basic methods as asynchronous. I tried to do something, and it's working but I'm not sure that it was implemented properly. Please ...
5
votes
1answer
282 views

Server that supports two types of connections

I'm wonder if my approach is correct. I'm trying to make a WinForms server that processes data from 3 sides: from bluettoh (InTheHand library) as source data which I need to process in server to ...
5
votes
2answers
126 views

Forced Async operation in a (event like) method

I have a piece of code that I am not feeling comfortable. I don't want to block the UI Read operation works synchronously (reading may broke 50 ms rule) Save operation supports async (returns ...
5
votes
1answer
150 views

Verifying that tasks are really async with AsyncDetector

Running tasks asynchronously can sometimes by tricky and no matter how careful I am, I sometimes forget some crucial part and my tasks run synchronously. I don't usually notice that until it's too ...
5
votes
1answer
2k views

Batch processing requests

I have a service which receives many requests and I am trying to optimize it by aggregating requests in batches and then processing batch which is much quicker than processing requests one by one. ...
5
votes
1answer
1k views

Is this SqlConnection / SqlCommand async wrapper both efficient and correct?

This is my first time writing async code, I intend to inject the interface IConnection into other classes in my project. Can you please tell me if the implementation class Connection, is the correct ...
5
votes
0answers
52 views

SQS subscriber pattern in background service

I have the below code to pull messages from a FIFO SQS queue. Using the while (IsRunning) loop makes me feel to question the code design. Is there a pattern I am ...
5
votes
0answers
133 views

Scheduler built with observables v2 (follow-up)

It would probably be too easy if the old Scheduler worked as intended being that simple. But an eye-openig review showed that from time to time it'll miss one ...
5
votes
0answers
2k views

Socket application using TPL

This is an application I wrote that allows multiple TCP clients to share a single TCP connection to a remote server (hosted project, and a demo). Traffic generated by the server is forwarded to all ...
4
votes
3answers
11k views

Simple SqlHelper which wraps ADO.NET methods

I am creating a simple SqlHelper which will simplify the ADO.NET method usage. Can someone please review this class for any issue or missing something? ...
4
votes
3answers
6k views

Asynchronous version of AutoResetEvent

This is my second attempt to create asynchronous version of AutoResetEvent. At first I tried to make it completely lock-less, but it turned out to be impossible. This implementation contains a lock ...
4
votes
2answers
771 views

Async & ContinueWith

I am implementing my own UnitOfWork for an EntityFramework-DataContext. I want to call ...
4
votes
2answers
1k views

Wrapper for a transfer transaction API

I'm looking for any kind of advice, like when or where to do exception handling, the overall library structure/layout, usage of classes/partial classes, code efficiency, naming conventions, and so on ...
4
votes
2answers
275 views

Asynchronously fetching Bitcoin orders and quotes

I have the following code to get data using async/await ...
4
votes
1answer
2k views

Connect to MySQL and fetch a list of customers asynchronously using C#

I am connecting with a database and returning values from a Web API controller. For better performance, I am doing it completely asynchronously with a new task. Am I doing it the correct way? Am I ...
4
votes
1answer
3k views

Concurrent/parallel ForEachAsync - proper handling of exceptions and cancellations

I've created an asynchronous parallel ForEach mechanism so I could enumerate an enumerable by N degrees of concurrency and process an action for each item. ...
4
votes
2answers
179 views

IsoStorageManager

A manager for a speedy async saving objects to isolated storage, using serialization from Newtonsoft.Json. A project to play with is here. ...
4
votes
2answers
155 views

Initializing multiple variables with different types using parallel calls

Consider the pattern below, where multiple async calls are made in parallel: ...
4
votes
2answers
254 views

Going to the thread pool and back using custom awaiters

I've figured out a way to switch threads in the middle of a method. The benefit of that seems super obvious to me: that's what everyone wants to do anyway, and splitting up methods, using callbacks, ...
4
votes
3answers
529 views

ListBox async filtering, cancelling previous task on filter update

I'm trying to come up with a nice way of filtering a ListBox asynchronously, to keep the UI responsive. The filtering gets fired off asynchronously each time the ...
4
votes
1answer
4k views

Cancellable progress form using async/await

Introduction: For a project I'm working on I used a BackGroundWorker to lift some heavy tasks away from the UI thread and report progress. For this I created some ...
4
votes
1answer
7k views

Async TcpListener

I'm trying to implement a TcpListener using the TPL. I'm not sure If I'm doing everything correctly though. I'm trying to keep the code as small as possible as well. It all works fine in a console ...
4
votes
1answer
159 views

CLI to bump package.json version and add git tags

I'm writing a command line app in node.js. At this stage, the app does the following: Get the version from package.json Update the package.json with a new version ...
4
votes
2answers
218 views

Fetch an array from API endpoint in async function

I've been studying javascript for the love of it, I'm currently learning how to use async functions and my code actually works, but I know there is always room for improving. I'm open to any help ...
4
votes
1answer
748 views

Calling common async code from a derived method

I'm implementing a number of classes in C# that have async methods. However, each of these methods needs to implement some boilerplate code that is common to all. Therefore I've implemented the common ...
4
votes
1answer
83 views

Async/Await Computation Expression

When writing asynchronous code in F#, one often needs to call methods in the .NET BCL that return Task or Task<T> rather ...
4
votes
1answer
179 views

TypeScript based Promise/A+ compliant, awaitable promise class for Node.js

This is yet another Node.js Promise implementation, but this is written in TypeScript, and it strives for type safety and clarity. The full project is located here. Feel free to download it and test ...
4
votes
1answer
899 views

Checking HTTP headers with asyncio and aiohttp

This is one of my first attempts to do something practical with asyncio. The task is simple: Given a list of URLs, determine if the content type is HTML for ...
4
votes
1answer
4k views

Parallel and Sequential array looping with async/await

Are these good implementations of parallel and sequential "extension" methods, and do they accomplish what I think they do? My understanding is that the first one is parallel because the await ...
4
votes
1answer
6k views

Asynchronously wait for a task to complete and do some async action while waiting

I have a long-running task. My goal is to create a method that will allow me to: Asynchronously wait for this task to complete While waiting on a task, do some async action once in a while. This '...
4
votes
1answer
1k views

Compressing a stream asynchronously, and returning a byte[]

Assuming I have to leave the contract intact (take byte[] and return byte[]), what's the correct way to structure this ...
4
votes
1answer
114 views

Scheduling using System.IObservable

With great inspiration from t3chb0ts ongoing work about scheduling, cron jobs etc. (last post here), I decided to make my own version of the Scheduler - using the observer pattern - as a learning ...
4
votes
1answer
720 views

Task-Based Overlapped IO In .NET

I've been working wrapping the Windows API's Overlapped methods in the more usable Task based approach. There isn't much information out there on doing this, so I've been flying blind apart from a few ...
4
votes
1answer
522 views

Asynchronous start/stop state transitions

I have a third-party object with asynchronous start and stop methods. Each start and stop may fail with exception. The object is not re-entrant, i.e. I can only call its start or stop method after the ...
4
votes
0answers
56 views

Wrap a callback method in an awaitable method

I'm using a .NET library which uses a pre-async/await type of asynchronicity. That is, it provides asynchronous (non-awaitable) method with a callback parameter. I'm trying to write awaitable ...
4
votes
0answers
100 views

Toggle any application feature ON or OFF

When testing or debugging applications it'd be often useful to be able to run it without certain features like committing things to the database, saving files, sending emails, reading files, executing ...
4
votes
0answers
243 views

Safely executing background tasks in parallel in ASP.NET Core

Context and initial idea I'm trying to teach myself the CQRS and Event Sourcing patterns by developing a simple ASP.NET Core application, loosely following Greg Young's example CQRS implementation on ...
4
votes
0answers
77 views

pool of python coroutines

Task control how much coroutines are running simultaneously with ability to stop the process from inside. Use case when scraping websites you want to control how much memory program consumes and ...
3
votes
2answers
2k views

Scraping HTML via async controller & classes + HTML agility pack

I've developed a simple application to grab golfer index scores from a website that has no API. The application works but is very slow, with 6 users that require updating takes 60 seconds. I've tried ...
3
votes
1answer
597 views

Am I using async C# correctly?

I have the following bit of code the calls out to two different command line components (each wrapped in their own Task) ...
3
votes
3answers
1k views

C# Async and DataContext access

I'm using a DataContext to insert an object. Currently it's working, but I'm feeling things could be done better. Method is called from UI (Using Caliburn Micro Binding). IsBusy is a property used by ...
3
votes
2answers
130 views

Named Semaphore with async calls

I have multiple distinct processes that need to access external resources that are rate limited. The processes are all async in nature and run in different applications. In times past I would just ...
3
votes
2answers
293 views

Using await to break long-running processes

I have a Node.js app / Web API that runs on an Azure app service with a single CPU. One of the functions needs to run for a long time, perhaps tens of seconds, while the server should continue to ...