Comments (4)
It's honestly a big pain to convert between these 2 cancelation token types efficiently. Since the CancellationTokenSource.TryReset()
API was added, I'm thinking it may be worth it to retire Proto.Promises.CancelationToken
and change all the APIs to accept System.Threading.CancellationToken
instead. This could be done with minor breaking changes by making an implicit cast that just calls ToCancellationToken()
.
from protopromise.
After some more thought, I've realized that even not caching the source does not fix the issue if someone stores the token somewhere and tries to reuse it after TryReset
has been called. The only real fix will be to retire Proto.Promises.CancelationToken
and adopt System.Threading.CancellationToken
in its place.
[Edit] Actually, this can be fixed by wrapping the registration in another object and using its finalizer to notify when the callback is dropped. (See Stephen Toub's solution) It's not perfect as it won't be observable until the GC runs and finalizers are invoked, but it at least solves the issue.
As a bonus, we can also use that to store a collection of WeakReference
s to those wrappers for the cache instead of doing the hacky way of extracting the source from the token.
from protopromise.
After attempting to fix this using the finalizer approach, I realized there is still another case I can't catch: It is possible the source has TryReset()
then Cancel()
called, then the source is collected before our finalizer is called, making it impossible to detect that the source was canceled after our callback was unregistered.
So I guess the only real fix is to retire Proto.Promises.CancelationToken
and adopt System.Threading.CancellationToken
after all...
from protopromise.
I think I may have actually figured out how to fix this without abandoning Proto.Promises.CancelationToken
. I'm working on #89 for it.
from protopromise.
Related Issues (20)
- Methods to troubleshoot UnobservedPromiseException HOT 24
- Fatal error when building macOS player HOT 3
- `PromiseYielder.WaitOneFrame().ToPromise()` waits an extra frame.
- Add analyzer to prevent accidental misuse of `AsyncEnumerable`
- Add `Promise.ParallelForEachAsync`
- Add async Linq extensions for `AsyncEnumerable` HOT 1
- Add `AsyncEnumerable.Merge`
- Add `AsyncEnumerable` convenient generators
- Decouple Progress from Promises HOT 1
- Add `Promise.Finally` overloads that accept `Func<Promise>` delegates
- Add overloads that accept `Span<T>` parameter
- Update readme with instructions to install analyzer in Unity
- Add `Channel` type
- Add parallel async Linq
- Add Unity `Awaitable` conversion to `Promise`
- Add Promise groups
- the README and CHANGELOG for 3.0 have the wrong year HOT 1
- Add `Promise.Each` to process operations as they complete
- Add `Promise.GetRetainer()` API
- Compilation error if to use it together with plugin for "oidc-client" (needed for Azure auth) HOT 9
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 protopromise.