Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we add something like PromiseContext.isExecutingNow? #53

Closed
lilyball opened this issue May 22, 2020 · 0 comments
Closed

Can we add something like PromiseContext.isExecutingNow? #53

lilyball opened this issue May 22, 2020 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@lilyball
Copy link
Owner

A problem with PromiseContext.nowOr(_:) is there's no easy way to tell in the callback whether it's being executed synchronously. If we register the callback from the main thread and use .nowOr(.main) we could use a local variable that we set to false after registering the callback, but this is a little awkward and requires knowing what thread you're registering the callback from.

The thought is maybe we could use TLS to store whether the context is executing synchronously or asynchronously and then expose this value in a property like PromiseContext.isExecutingNow. All cases where a promise callback is invoked should be directly nested inside a call to context.execute so there should be no risk of returning stale info from this property, but this should be audited.

Question: In order to implement .nowOr we piped an isSynchronous flag through the seal enqueuing and context execution. Could we instead use TLS that's set when the seal runs its enqueued callbacks and query it from the context? I didn't implement it that way to begin with because I wasn't sure if there was any way to end up with stale data at the context.execute call (e.g. if there are any context.executes that aren't direct children of a seal.enqueue), but it may be safe to represent it that way.

@lilyball lilyball added the enhancement New feature or request label May 22, 2020
@lilyball lilyball added this to the Next milestone May 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant