wg-async
wg-async copied to clipboard
Asynchronous drops
Brief summary
As a C# developer I really enjoy async disposals. The idea behind them is to have something like RAII, but non-blocking which is very important in case of handling IO (files, network connections, etc.).
The following example demonstrates usage automatic non-blocking buffer flushing of a stream and closing handles:
await using var stream = new SomeStream();
await stream.WriteAsync(/* data */);
Without using asynchronous disposal the code might block the current thread till the operation completes while it would be much better to schedule the operation using io_uring or completion ports, and reuse the current thread for other workload.
The idea can be useful not only for IO heavy applications, but also for cases when some action must be executed on a dedicated thread or in background and later the execution should continue on the original thread. A good example where it might be useful is UI: the main thread is for user interface updates and input handling, while any background for long running operations.
Optional details
- (Optional) Which character(s) would be the best fit and why?
- (Optional) Which project(s) would be the best fit and why?
- Any which requires efficient thread utilisaion.
- (Optional) What are the key points or morals to emphasize?
- Write some morals here.
See also here for a discussion of where async Drop could be very useful to solve an existing problem: https://internals.rust-lang.org/t/async-await-the-challenges-besides-syntax-cancellation/10287/2