Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top