-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
Add standard convenience functions for creating Promises to resolve groups of Futures. #1844
base: develop
Are you sure you want to change the base?
Add standard convenience functions for creating Promises to resolve groups of Futures. #1844
Conversation
…roups of Futures.
Not expert in this area, I wonder have you evaluated Franco's code in relation to this. |
thx.promise is not compatible with the |
but you read understood and learned from Franco, or did you just consider if the code was compatible - because that would be disappointing. There are creatives you learn from and I suspect Franco for haxe is one of them, and if you learnt nothing from his work then your commit is probably shallow? Please take another look at franco's stuff and evolve. |
Not sure why thx.promise would be relevant here, as far as i can tell this is just a few utility methods making existing lime code more convenient to work with. i do wonder if the PromiseResult would be simpler as an Enum tho, just my two cents. enum PromiseResult<T> {
Pending;
Fulfilled(value:T);
Rejected(error:Dynamic);
} |
* A set of static utility functions for working with Promises. | ||
* This includes functions which resolve groups of Futures. | ||
*/ | ||
class Promises { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add the functions to Promise
?
I just went to make some refinements to this PR, and tried to implement your suggestion to add the static functions to the However, I discovered that since Promise is an Using |
Right, of course. I've always been unclear on why it was made generic in the first place. |
Oh yeah I reworked to remove PromiseResult a while back but forgot to push it, here it is. |
I just merged #1846, so if you target 9.0.0-dev, you'll be able to add these directly to the class. |
Several convenience functions which mostly mimic promise handling functionality from JavaScript. Definitely standard enough to be part of the base library.
Promises.all()
resolves an array of Futures, completing when all of the Promises are fulfilled or any of the Promises are rejected.Promises.allSettled()
resolves an array of Futures, completing when all of the Promises are fulfilled or rejected.Promises.any()
resolves an array of Futures, completing when any of the Promises is fulfilled or all of the Promises are rejected.Promises.race()
resolves an array of Futures, completing when any of the Promises is fulfilled or rejected.Good example use cases include calling
lime.utils.Assets.loadImage()
for each of an Array of images; you now have multiple promises, and want to wait for all of them to resolve before continuing.