I have a Promise chain like this
firstly {
Network.shared.getInfo()
}
.then { info in
Network.shared.getUserDetail(info)
}
.then { detail in
Network.shared.getAddOn(detail)
}
.done { addOn in
//do stuff with addOn
}
.catch { error in
}
and I need to have all values (info, detail and addOn) in the .done
Promise block. Is there a way to extend visibility or pass values throught Promise ?
I can’t use when(fulfilled: [])
because each value depends from the previous one.
Thanks.
2
Answers
You need to create variables to assign your values to,
Ex:
You could propagate the inputs from your previous promise to the next promises by wrapping the new value and the previous one(s) in a tuple.
Alternatively, you could change your methods to return tuples themselves or to return a type which wraps the input arg and the newly generated return value.
So for instance change
Network.shared.getUserDetail(info)
from returning justUserDetail
to returning(UserInfo, UserDetail)
.