-
Notifications
You must be signed in to change notification settings - Fork 295
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
Feature request #134
Comments
Totally agreed, some way to handle cases where a promise has already resolved before reaching us (possibly a |
https://github.com/google/promises/blob/master/Sources/FBLPromises/FBLPromise.m#L235 if we have a way to not always dispatch_group_async here, and I do not see the need for dispatch group if we do not need waiting? and it seems only need waiting for testing purpose? |
I think what you're looking for is await? |
Await will not work because the “then” method uses the main queue, and main queue wont drain while we wait and we’ll be stuck forever. |
Of course you shouldn't use await on main queue. Why can't you use a custom background queue? numberPromise.then(on: backgroundQueue) { number in
return String(number)
} |
say click a like button and we want to update the ui immediately then the promise1 we want it to be sync to run some logic and spit out the result of update like or not. then another promise2 after promise1 will dispatch to background as a "then" of promise 1. Another similar example is that we override TextView's Also we do not have control of promise1 (user provide that) meaning we can not just use [Promise resolvedWithValue]; |
If you disclose the full source code, it will be more helpful. You shouldn't be using promise if you need the value synchronously on the main queue. Because by definition, you don't know how long the promise will take to be resolved. |
Hi Max, From what you've described, it seems like you're trying to use a promise to implement a synchronous method (which happens to be a predefined delegate call, so you can't just make it async), so have to really wait for the result somehow. As I understand, More context for your example would definitely help. It's unclear where that Alternatively, you may consider storing the promise result somewhere when it's resolved for the first time and check that value instead in a delegate method, since any promise resolves only once. The reason why Promises doesn't support direct queries like
Actually, consider completion handlers. Those should always be Thanks. |
I came here accidentally while looking for some promise libraries.
As an example of implementation please check this C# implementation of promises I use for Unity3D projects. This allows for such synchronously available data inclusion into promise chain. I hope I understood the initial issue idea correctly. |
I have this list of promises chained by then, while current then will dispatch async to main to next runloop, while we want the work to be done immediately/inplace when some condition is met.
Say user type on keyboard and triggered the list of promises to be chained, while we want the the work of then to be called synchronously instead of just return. sth like
if(IsOnMain && promise.isFulfilled) { workOfThen()}
Is there a way to expose api like a synchronousThenIfPossible? Thanks
The text was updated successfully, but these errors were encountered: