zesterer / pollster Goto Github PK
View Code? Open in Web Editor NEWA minimal async executor that lets you block on a future
License: Apache License 2.0
A minimal async executor that lets you block on a future
License: Apache License 2.0
I know pollster
tries to be as minimal as possible, but this would be very neat.
Is there any interest in hosting this as part of the official repo?
pollster
's Cargo.toml
specifies the license
Line 10 in 9cd9eed
but other tooling might not find this, e.g. github currently does not display a license button on the sidebar.
Building a crate which indirectly depends on pollster
suddenly started failing with the 0.2.4 release:
error[E0658]: use of unstable library feature 'wake_trait'
--> /home/andrew/.cargo/registry/src/github.com-1ecc6299db9ec823/pollster-0.2.4/src/lib.rs:19:27
|
19 | task::{Context, Poll, Wake, Waker},
| ^^^^
|
= note: see issue #69912 <https://github.com/rust-lang/rust/issues/69912> for more information
error[E0658]: use of unstable library feature 'wake_trait'
--> /home/andrew/.cargo/registry/src/github.com-1ecc6299db9ec823/pollster-0.2.4/src/lib.rs:104:5
|
104 | / fn wake(self: Arc<Self>) {
105 | | self.notify();
106 | | }
| |_____^
|
= note: see issue #69912 <https://github.com/rust-lang/rust/issues/69912> for more information
error[E0658]: use of unstable library feature 'wake_trait'
--> /home/andrew/.cargo/registry/src/github.com-1ecc6299db9ec823/pollster-0.2.4/src/lib.rs:103:6
|
103 | impl Wake for Signal {
| ^^^^
|
= note: see issue #69912 <https://github.com/rust-lang/rust/issues/69912> for more information
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0658`.
error: could not compile `pollster`
Please yank 0.2.4 and release it as 0.3.0 instead, as this appears to be a breaking change..
Especially when passing around functions, trying to use async in wasm (particularly without WASI) is currently an absolute mess. I've been stuck for weeks on one particular issue in a project, and finally came across this, and it worked. Perhaps it should be mentioned as a usage in the README?
I had a quick look at it. It does have an unsafe without comment clarifying why it's guaranteed to be safe, which is unfortunate. On performance, it seems to be in the same league as async_std::task::block_on
.
Now for the bad news, this deadlocks, and it doesn't on async_std::task::block_on
, nor on futures::executor::block_on
:
use
{
std :: { thread, sync::atomic::{ AtomicUsize, Ordering::SeqCst } } ,
tokio :: { sync::mpsc } ,
};
// queue size for the bounded channel, 16 is same as actix default size.
//
const BOUNDED : usize = 16;
const MESSAGES: usize = 100_000;
fn main()
{
let (mut a_tx, mut a_rx) = mpsc::channel( BOUNDED );
let (mut b_tx, mut b_rx) = mpsc::channel( BOUNDED );
let thread_a = thread::spawn( move ||
{
pollster::block_on( async
{
while let Some( msg ) = a_rx.recv().await
{
b_tx.send( msg ).await.expect( "send on b" );
}
});
});
let thread_b = thread::spawn( move ||
{
pollster::block_on( async move
{
for _ in 0..MESSAGES
{
a_tx.send( () ).await.expect( "Send on a" );
}
});
});
pollster::block_on( async move
{
let sum = AtomicUsize::new(0);
while sum.fetch_add( 1, SeqCst ) < MESSAGES
{
b_rx.recv().await;
}
assert_eq!( sum.load( SeqCst), MESSAGES + 1 );
});
thread_a.join().expect( "join thread_a" );
thread_b.join().expect( "join thread_b" );
}
Some proper testing is in order I think. Good luck.
The functionality provided by this crate is identical to futures::executor::block_on
.
I have the following natural questions that I feel deserve to be mentioned in the readme:
What are the differences between the two versions?
If I already depend on futures
with the executor
feature, is there any reason to prefer pollster over futures?
If pollster is preferred in that case, why isn't the futures version implemented through pollster?
I'm aware that the readme broaches this topic to some degree t but I feel that the futures crate version deserves special mention because it is not (?) a heavy weight executor part of a larger async framework.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.