Nested invokeAsynchronous and invokeLater

Let’s say I have functions long_taking_function and long_taking_function2. Both take a long time. Is it considered bad practice to have ‘nested’ invokeAsynchronous and invokeLater? If so, how can I improve this?

def long_process():
    bla = long_taking_function()
    if bla:
        def send_back():
            if bla:
                def long_process2():
                    bla2 = long_taking_function2()
                    def send_back2():
                        if bla2:
                            ...
                        else:
                            ...
                    system.util.invokeLater(send_back2)
                system.util.invokeAsynchronous(long_process2)
            else:
                ...
        system.util.invokeLater(send_back)
    else:
        ...
system.util.invokeAsynchronous(long_process)

You can nest as shown. Another possibility would be to use just one asynchronous task and using CompletableFutures to pause that background and retrieve information from the foreground. See this discussion involving my later.py script module:

1 Like

I love how responsive you and how useful your answers always are. Thanks a lot!

1 Like