Comments (7)
@orbli Can you provide a minimal example to reproduce the error?
from async-scoped.
use std::time::Duration;
use async_std::task;
use async_scoped::scope_and_block;
async fn some_task() {
println!("some task");
}
async fn spawned_task() {
scope_and_block(|s| {
s.spawn(some_task());
});
}
async fn async_main() {
task::spawn(spawned_task());
task::sleep(Duration::from_secs(1)).await;
}
fn main() {
task::block_on(async_main());
}
from async-scoped.
It seems to be an issue in async-std not allowing block_on inside a spawn. The following example also causes the same error (tested with async-std release 1.6.3).
#[test]
fn test_recursive_block() {
task::block_on(async {
task::spawn(async {
task::block_on(async {
eprintln!("Hello block!");
})
});
})
}
from async-scoped.
i agree your answer, sorry 😂😂😂 let's raise this to async std and see if they offer any help
from async-scoped.
@orbli This behaviour of async-std may be necessary to prevent deadlocks, as I believe they internally use a fixed number of worker threads to process the futures. See for instance this issue.
Unfortunately, the only safe way provided in this crate currently uses a block_on
construct. I have not been actively following the async rust developments recently, so I am not sure if there is an alternative. Let us see if async-std authors offer some interesting ideas around this issue.
from async-scoped.
@orbli It seems the panic only happens in recent releases of async-std. If it suffices for your use-case, you can consider fixing the version of async-std in your project to 1.4.x
(using something like async-std = "~1.4.0"
) in Cargo.toml.
Also, replacing the task::block_on
with either smol::block_on
or futures_lite::block_on
seems to work. I should look into using one of these internally, but I am not a 100% sure how these crates plan to progress in the future. Will try to dig into code, and issues on this.
from async-scoped.
v0.5.0 and above do not have the panic
from async-scoped.
Related Issues (19)
- tokio? HOT 5
- Tokio 1.0? HOT 3
- Compilation error after Rust nightly 2021-01-10 HOT 12
- Compile fails when using async-std without the attributes feature enabled HOT 2
- Question about `spawn_cancellable` HOT 6
- Compilation error, failed inference on closure HOT 3
- Return result containing references HOT 2
- Support for spawn_blocking HOT 5
- Support for user-provided runtime HOT 5
- Why is async_scope blocks some writes to file? HOT 2
- Allow async block in `scope_and_block` and `scope_and_collect` HOT 1
- docs bug
- Question: using async-scoped with for_each_concurrent HOT 2
- Release async-scoped 0.9 version HOT 7
- scope_and_collect should return results in order of submission HOT 2
- Limiting concurrent tasks HOT 1
- handle references in function results HOT 4
- Doc request: full minimal working example, including main HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-scoped.