Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift & PromiseKit: Resolving ALL promises from a loop

I'm looking for a solution in Swift3 to resolve a dynamic number of promises all at once, e.g. like this sample in JavaScript:

var promises = [];
for(var i = 0; i < 5; i++) {
    var promise = $http.get('/data' + i);
    promises.push(promise);
}
$q.all(promises).then(doSomethingAfterAllRequests);

https://daveceddia.com/waiting-for-promises-in-a-loop/

There was a library call 'Craft' for Swift2 that could do that (https://github.com/supertommy/craft), but it's no longer maintained.

Does anyone know if or how I could do that with PromiseKit or another library?

Thx a bunch!

like image 365
Thread Pitt Avatar asked Apr 29 '17 21:04

Thread Pitt


People also ask

What is SWIFT stands for?

SWIFT is an acronym for the Society for Worldwide Interbank Financial Telecommunications and may also be referred to as a CIC code.

What country owns SWIFT?

History. SWIFT was founded in Brussels on 3 May 1973 under the leadership of its inaugural Swedish CEO, Carl Reuterskiöld (1973–1989), a former employee at Wallenberg-owned Skandinaviska Enskilda Banken, and was supported by 239 banks in 15 countries.

What countries are in SWIFT?

SWIFT is overseen by the G-10 central banks (Belgium, Canada, France, Germany, Italy, Japan, The Netherlands, United Kingdom, United States, Switzerland, and Sweden), as well as the European Central Bank, with its lead overseer being the National Bank of Belgium.

What does SWIFT actually do?

The SWIFT payment network allows individuals and businesses to accept/send international money via electronic or credit card payments. This can be done even if the customer or vendor uses a different bank than the payee. The network is a place for secure financial messaging.


1 Answers

You can look into when which may provide what you need and is covered here.

Use the loop to put your promises into an array and then do something like this:

when(fulfilled: promiseArray).then { results in
    // Do something
}.catch { error in
    // Handle error
}
like image 138
CodeBender Avatar answered Oct 06 '22 18:10

CodeBender