Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of async_std::sync::Arc?

Tags:

rust

I understand why structures that may block the current thread, like Mutex and RwLock, need to be reimplemented to rely on the futures/waker API, but why does it need to do so for Arc?

As far as I understand, no operations on the standard Arc are blocking, and in the latest version, async_std::sync::Arc is just a reexport of std::sync::Arc.

Is this future-proofing, in case a future implementation of Arc needs to rely on blocking?

Which one should I use in async code, and why?

like image 363
b0fh Avatar asked Dec 13 '19 08:12

b0fh


1 Answers

The point is to ease the transition from std to async_std as much as possible.

The description of the crates starts with:

This crate provides an async version of std.

And one of its descriptive feature is:

Intuitive: Complete parity with the stdlib means you only need to learn APIs once.

As for the blog post that introduced it, it clearly mentions that async_std is mean to be a drop-in replacement of stdas much as possible:

With async-std​, all that’s needed is replace std​ with async_std​, add the prelude​, and sprinkle in a few .await​s

(emphasis is mine)

Given all that, it makes sense that the developers of async_std would chose to re-export all types from std that don't need to be adapted to async: Users don't need to worry about whether types are async or not and don't need to worry about what to use.

like image 64
mcarton Avatar answered Oct 19 '22 05:10

mcarton