Answer the question
In order to leave comments, you need to log in
How to implement a chain of callbacks in python?
In javascript I can do like this:
var some = 100;
var param1 = 1;
func1(param1, function(res1) {
var param2 = res1 + some;
func2(param2, function(res2) {
// ...
});
});
$some = 100;
$param1 = 1;
func1($param1, function($res1) use ($some) {
$param2 = $res1 + $some;
func2($param2, function($res2) {
// ...
});
});
Answer the question
In order to leave comments, you need to log in
in python, there are only lamba as anonymous functions, which have very strict restrictions, for example, that their body can contain only one expression, i.e. in plain language - there can't be very much logic inside a lambda. therefore, for more complex structures, you need to create named functions, for example:
some = "hello"
def func_1():
print some
one_more = "world"
def func_2():
print some, one_more
def func_3():
print "hello world"
return func_99("bla-bla", func_3)
return func_100("bla-bla", func_2)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question