Comments (6)
I need to document that. But there is a class called FutureBatch.
FutureBatchOf is a typesafe version. But it requires all the futures to be the same type.
FutureBatch is a type alias of FutureBatchOf.
And if has a var "future" which will succeed iff all of its subfutures succeed.
They also execute in parallel. The result is an array [Any]
from futurekit.
Didn't mean to close this yet.
I'll get the documentation and example up this weekend.
from futurekit.
Well, I think there should be more options of handling this ... Like complete if any of the futures is completed ... complete if all the futures are completed, etc ..
from futurekit.
So the current implementation waits for all to finish. Which I use a lot in my code. It also keeps error handling simple and reliable.
There is also an internal future that first returns a an array of Completion<Any>
if you want to query the individual futures results. But I never have used that. I mostly just want to fail if any fail. One option I have considered adding is to stop immediately after the first failure. (It currently doesn't do that). Which hasn't been a huge problem for my existing apps so I haven't added that feature. But might be worth adding but it does add complexity.
It wouldn't be hard to build a "return a value immediately if any finish". I can show an example of how to do that. But not sure if it should be part of FutureBatch or just included as an example. (Cause it's dead simple).
For that you can just create a single Promise, and than iterate through an array of Futures calling onComplete or OnSuccess that try to complete the Promise. And use the future from that Promise.
Do you care if the others succeed? Should they be canceled?
I've been intentionally trying to remove complexity or confusion from the initial launch.
from futurekit.
Added this:
#5
Which changes FutureBatch a bit. Still need to add a full set of test cases. But it should do what you want.
There are now 3 vars
completionFuture
- returns an array of Completions<T>
. Always returns '.Success' with an array of completion values. Does't finish until all sub-futures do.
batchFuture
- returns an array[T]
. Will Fail if one sub-future fails. Will return Cancel if no Fails, but one sub-future is canceled. Completes only after all sub-futures have completed.
future
- exactly like batchFuture
- EXCEPT it will stop immediately if one of the sub-futures returns Fail or Cancel. It doesn't wait for other sub-futures to complete.
Also add
cancelRemainingFuturesOnFirstFailOrCancel()
and cancelRemainingFuturesOnFirstFail()
which will try to cancel other sub-futures if one of the sub-futures fail. (To help speed up halt/cleanup).
onEachComplete()
which lets you define a block that will run as soon as each sub-future completes.
I think this should be flexible enough to cover must needs for dealing with lots of sub-futures.
I killed append
(for now)which would let you add a new future to an existing batch (that has already started). Both cause I think it may lead to difficult to manage logic AND it was hard to implement once I added onEachComplete()
and'cancelRemainingFuturesOnFirstFailOrCancel()
. Might return in a future version of FutureKit.
from futurekit.
This has been closed in the latest releases.
from futurekit.
Related Issues (20)
- Add Linux Support
- Never-ending process when building or archiving. HOT 4
- Cancellation deadlocks HOT 3
- Question: Cancellation of promises HOT 6
- Question: FutureKit 2.0 changes HOT 2
- Better description under title HOT 3
- Swift 3.0 migration HOT 9
- [question] any dedicated way to separate the construction and execution of the promise/future? HOT 1
- [question] flatmap for futures? HOT 2
- make return value of onComplete discardable
- Warnings in the new XCode Version 8.3.2 HOT 2
- Xcode 9.0 support? HOT 1
- Allow futurekit to build via carthage with Xcode 9 HOT 3
- mapAsOptional() has impossible function signature HOT 2
- Combining multiple requests HOT 1
- Build error on Xcode 9 Beta 3 HOT 4
- 3.0.1 release? HOT 2
- Crash in Synchronization.swift HOT 6
- Error in completeWithSuccess() on Swift 4 HOT 1
- Documentation link not working
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 futurekit.