Open gavrix opened 7 years ago
When chaining multiple promises together, each step only triggers execution when previous step is complete. That means, for following promises cancellation token hasn't even been created yet until current finishes.
Calling cancel
will call cancellation action on currently executing Promise
and will prevent following promises to be started.
Although not part of this question, it's worth noting that following Promise
s in the chain don't exist until current step completes. E.g.:
let chain = makeAsyncPromise()
.then { step1_result in
return makeAsyncPromise2(step1_result) // #1
}
.then { step2_result in
return makeAsyncPromise3(step2_result) //#2
}
.whenComplete { step3_result in
print("Final value from step3 is \(step3_result)")
}
line #1
will not be called (and Promise instance won't be created) until step1 resolves. Similarly, line #2
will not be called (and Promise
instance won't be created) until step2 resolves.
Oh, right! That's a good point I should have caught.
Now I'm not sure if it's worth putting that in the doc, because other people might wonder, or not, because it's obvious now that my head is screwed on straight.
Question from @psycotica0-shopify: