Comments (6)
Thanks for pointing this out. As we discussed, I've moved to using futures::Abortable
which also simplifies the code base. FIxed in 0.7.0.
from async-scoped.
It seems that makes the future cancelled instantly.
from async-scoped.
Another question: What is the difference between CancellableFuture
and futures::future::Abortable
?
If I only spawn one single future, then is futures::future::Abortable
a more favorable choice?
from async-scoped.
Another question: If cancellation is implemented correctly (e.g. all spawned futures are cancelled when the scope is dropped), then how unsafe fn scope
is?
Is it possible that we have a safe interface (at least for use case when we only spawn one single future)?
from async-scoped.
In this line, why the code is
*guard
instead of!*guard
?
I believe you're right: the if condition should indeed be inverted. Should add a test for this functionality, and fix this.
Another question: What is the difference between CancellableFuture and futures::future::Abortable?
A quick glance does suggest that we could swap it out for Abortable
. I suppose the Scope
structure will hold the AbortRegistration
and use that in spawn_cancellable
. Would need a more thorough look at the semantics of Abortable
to ensure the safety requirements are withheld: nothing within the inner future should be accessed once aborted as it may contain references that have expired.
Another question: If cancellation is implemented correctly (e.g. all spawned futures are cancelled when the scope is dropped), then how unsafe fn scope is?
The safety issue with Scope
creation is that there is no guarantee that the Scope
is not forgotten via mem::forget
instead of being dropped. Thus, the cancellation / abort mechanism might not kick in before the references used within the spawned futures expire. This is why the only safe interface is to spawn and block on the scope.
Thanks for looking at it and your findings. Would you be able to contribute a PR to fix the guard logic, and may be also to verify and switch over to Abortable
?
from async-scoped.
Thank you for the detailed answer.
I have found a workaround for my use case, therefore currently I have no strong motivation for a PR to this project.
However, I believe this crate is useful under certain circumstances and I might have a revisit in the future.
from async-scoped.
Related Issues (9)
- Compilation error, failed inference on closure HOT 3
- Return result containing references HOT 2
- Support for spawn_blocking HOT 5
- panic when calling scope_and_block HOT 7
- 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
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.