问题
I am having a hard time using PromiseKit 6. I have several asynchronous functions which need to run one after the other so I need to chain them. I was wondering what's the correct way to use them. Also, no help from Here. So, as in PromiseKit6
, you have to return a Promise from then
, which is what is specifically giving me headache.
I have an example:
First Function
func A()->Promise<[String]> {
return Promise { seal in
//Do some Asynch operation and got String Array , `temp_Array`
seal.fullfill(temp_Array)
}
}
Second Function
func B() -> Promise<[String]> {
return Promise { seal in
//Do some Asynch operation and got String Array , `temp2_Array`
seal.fullfill(tempArray)
}
}
Third Function
func C() -> Promise<Void> {
return Promise { seal in
//Do some Asynch operation and got String Array , `tempArray`
seal.fullfill_()
}
}
Now I want to call all three Functions in Chain
like below
firstly {
self.A()
}.then { (Array_Receieved_From_A_When_Completed ) ->Promise<[String]> // Confused with this return
//Do some operation with `Array_Receieved_From_A_When_Completed `
self.B() /* How to call that function */
}.then {(Array_Receieved_From_B_When_Completed ) -> Promise<Void> {
//Do some operation with `Array_Receieved_From_B_When_Completed`
self.C() /* How to call that function */
}.done {() in {
}.catch(error) in {
print(error)
}
How should I manage this? How data from one then
to other then
goes? I was fed up with handling asynchronous functions and thought of using PromiseKit
but this is also giving a tough time.
来源:https://stackoverflow.com/questions/62780222/how-should-i-chain-multiple-promises-in-promisekit-6