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
1
vote
0answers
25 views

async/await vs promise.then() for simple task

I made a helper function for drawing the map(OpenLayers), then another helper function for fetch(axios.get) the map URL, So my question is, switch from .then() to async/await loadMap_before() to ...
2
votes
0answers
62 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. ...
7
votes
1answer
134 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
45 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 ...
1
vote
1answer
49 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
39 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
141 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
75 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
69 views

Wrapping an asynchronous generator in Python

Since Python 3.6 and PEP 525 one can use asynchronous generator: ...
0
votes
0answers
27 views

python asyncio with queue

Working on my asyncio chops. Queue pattern works for multiple scenarios. Classic network example below, other potential scenarios - file processing, db access, etc... ...
2
votes
1answer
78 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
vote
0answers
26 views

Mern stack app on error handling, async await, try-catch and avoiding DRY in controller functions

I'm looking for a review of my backend code on how to keep it more DRY. I see a lot of repetition in validation part of email and password, also I need some advice on if I have used the try-catch and ...
1
vote
0answers
26 views

Memoization of slow URL get requests

Purpose of this small module is to allow memoization of slow URL get requests. I intend to send many of these to download a bunch of files from internal (rather slow, old) website. Some requests may ...
2
votes
0answers
19 views

Web API wrapper design and sharing EF database context

I'm trying to keep my sanity while working with a legacy winforms application that uses an web api, both maintained by my team. In the past we have multiple cases of methods using wrong api endpoints,...
1
vote
0answers
49 views

Awaiting the completion of a server request

I faced the following problem. I have a Server object server which exposes TriggerStateChangeAsync() which return an ...
1
vote
0answers
50 views

Execute command using `asyncio.create_subprocess_shell` and yield lines of stdout, stderr and finally the return code

My task is to run a subprocess using asyncio.create_subprocess_shell and yield the lines of output. I am using asyncio to avoid ...
3
votes
0answers
43 views

Is my async websocket python code correct?

This is the first time I am posting here, so please go easy on me : ). I am also writing for the first time python code which uses async / ...
1
vote
0answers
90 views

create vscode tree item extesion

I use the following code to add tree item to vscode extension, Im getting the data and build the tree according to the entries I got, the code works. As I new to typescript I appreciate your feedback'...
0
votes
1answer
46 views

Registering a user and login

I have these following controller functions for registering a user and login, in my app, and I want to make it more clean and maintainable. Probably by using ...
4
votes
1answer
272 views

Cancelling A Task Without Cancellation Token

Some Task methods don't take cancellation tokens. This is a problem because some long-running tasks may never finish and there is no way to send them a cancellation request. This seems a bit dodgy to ...
2
votes
1answer
88 views

Cross-thread label countdown

Short and sweet... I wrote a cross-thread method that displays the countdown [in seconds] of a delay on a label. I'm fairly confident it's far from optimal, so I'm in need of that glorious ...
4
votes
1answer
352 views

Using async / await with dynamic import() for ES6 modules

I am experimenting with the best way to standardise my dynamic import() expressions when importing javascript modules. import() ...
1
vote
0answers
58 views

Extension method: Task<T>.CoalesceAwait

There has been ongoing concern about the question of awaiting a task that could possibly be null, as when using null-coalescing operators. Consider the following: ...
3
votes
0answers
66 views

HTTP download function in Rust (async/await)

Why am I fighting the compiler? - Wrote this, which works, but I feel like I'm breaking every rule in the book: ...
1
vote
1answer
89 views

Refactoring try blocks with async/await

I have two functions which I would like to simplify. They have largely the same logic, but one is asynchronous and uses one await in a try block. I'd like to have the logic in one place, but could not ...
1
vote
0answers
146 views

SelectAsync With Max Degree Of Parallelism

I have been looking for the best approach to creating an extension method that would give me the ability to select in a linq query using async/await with a max degree of parallelism. I'm aware that ...
3
votes
2answers
373 views

Adding a cancellation token to TcpListener.AcceptTcpClientAsync()

There is no facility in TcpListener (or for that matter Socket) to close a listening socket that is waiting for a connection without throwing an exception. After running up a test bench with 8 ...
4
votes
1answer
217 views

Python: Asyncio object-oriented style

I'm seeking a review of some code I've written for a small personal project. The project is not yet mature enough for any domain specific details to be of concern - but I'm happy to provide further ...
1
vote
0answers
261 views

Handle aws lambda function containing multiple axios call

I have written an aws lambda function in NodeJS which has 2 async axios call. ...
6
votes
0answers
144 views

TPL Dataflow - Timer Action Block

I'm new to TPL Dataflow and was looking for an action block to basically push an object on a timer - specifically to produce heartbeats on every interval. I was unable to find anything out of the box ...
3
votes
0answers
924 views

Hosted service for queuing and running tasks in parallel in ASP.NET Core

I am attempting to construct a background service for an IIS-hosted ASP.NET Core project that basically queues tasks and runs them, and I decided to go with the ...
0
votes
1answer
440 views

Cancel Long Running Query using Cancellation Token AND SqlCommand.Cancel()

I need to be able to cancel a long running query programmatically through our application. The code below will kick off a long running query and give control back to the main thread. At any ...
0
votes
1answer
134 views

Mixing Async and Sync in same HTTP request ASP.NET Core C#

Is it bad practice to mix async and sync call in same ASP.NET core API call? For example, in following code method CropBlackBroderOfAnImageAsync is an async method....
3
votes
2answers
79 views

Cleaner Way to Structure Asynchronous Code

The purpose of the code is to allow the user to select directories that will be crawled recursively in order to find particular files or file types to analyze en masse. The thing to bear in mind is ...
1
vote
0answers
72 views

Async scheduler that executes commands multitthreaded

I have made a multithreaded command runner that works, just wanted to share the code and see if you guys can see any pitfalls. Comments are not part of actual code ...
3
votes
0answers
190 views

Python AsyncIO pipeline

I wrote a small snippet to implement asyncio Pipeline - object that connects together Layers, and lets them create and pass ...
3
votes
1answer
71 views

Token Bucket context manager for rate limiting async calls

I've written a class that implements something akin to the token bucket algorithm so that I may rate limit aysnc HTTP requests made from my application. The code works but I'm still not sure if it ...
2
votes
0answers
36 views

Passing JSON files through an API - node async

I am writing a small program which reads some JSON files, passes the content to an API, then saves the response in some more JSON files. A pretty simple task, and the code works fine, but I have been ...
4
votes
1answer
91 views

Data encryption / decryption on Node.js

I've implemented my first data encryption / decryption methods on Node.js. Although it might look similar to hundreds of sample implementations available online, I'm curious to get a feedback. I'm ...
8
votes
1answer
416 views

Operation logger

GitHub, NuGet This component traces execution in a logical order instead of chronological as everybody else :) For example, the following code: ...
4
votes
1answer
1k views

Asynchronous parallel ForEach implemented using Task.Run

I wrote a simple implementation of aysnc parallel.ForEach( ... ) All it really does is create a list of tasks and wait for them all to complete and aggregate the ...
2
votes
1answer
83 views

Python task runner with asyncio

I'm trying to a write super simple task runner with asyncio. Basically, my goal is to run 100 requests to google as tasks, whilst also being be able to handle tasks being added at a later time. <...
6
votes
0answers
117 views

Single-threaded fully asynchronous server, with a SocketSelector that dispatches events

I need a fully asynchronous single-threaded server written using .Net Core. Searched for options and, surprisingly, did't find any. So I decided to write a simple prototype. Borrowed idea from python'...
3
votes
1answer
99 views

LINQ for extracting N bottom items (async streams)

source.Bottom(n, x => x) should be the same as well known LINQ source.OrderBy(x => x).Take(n) but is more memory/run-time ...
7
votes
2answers
382 views

Network helper class with retry logic on failure

I wrote an helper class which allow me to request the body content from a site that is created by AJAX, for doing so I'm using <...
6
votes
1answer
99 views

Custom HttpClient implementation for third part usage with sync/async calls

I'm doing an implementation of HttpClient that is built in a NET Standard project, which will be used as a base to build and process JSON requests/responses for a third part REST API. Client is built ...
10
votes
4answers
3k views

AsyncDictionary - Can you break thread safety?

This class is an Async/Await wrapped Dictionary. Of course it doesn't technically implement IDictionary, but the functionality is basically the same as an IDictionary. It achieves similar ...
1
vote
1answer
92 views

Async Tcpwriter and Reader

I currently have a class that I want to serialize/deserialize messages sent to this socket. My plan was to use Task.WhenAny() to monitor 2 tasks (Either watch ...
2
votes
0answers
65 views

Await data coming from an event [closed]

This is a USB related question, but the problem is not USB specific. When reading data from a USB endpoint, there are two patterns I am concerned with. Request/Response like HTTP (done over the Bulk ...
3
votes
0answers
276 views

Example Multiple Async Await Calls Javascript

I need to make an unknown number of api calls, up to 5 max probably. But most samples I've seen show only a couple of async calls so are effectively hard coded to the number of calls being made. This ...

1
2 3 4 5 6