I want to create a deferred as follows:
f1(x1)
and f2(x2)
are performed in parallel (so to speak)
and after they finish, I run f3()
If I had the same parameters, I'd run:
d = Deferred()
d.addCallbacks(f1)
d.addCallbacks(f2)
d.addCallback(lambda x: f3())
d.callback(x1)
So that I pass x1
to both f1
and f2
. But I need f1
to get x1
and so forth.
How can I 开发者_运维知识库do this?
Thanks.
I am not sure, if I understood your use case right, but this seems to be something, where a DeferredList would work particularly well.
d1 = function_that_returns_a_deferred_1(x1)
d2 = function_that_returns_a_deferred_2(x2)
d = DeferredList([d1, d2])
d.addCallback(lambda ign: f3())
This way, f3 will only be executed once both d1 and d2 have completed.
精彩评论