Skip to content

Question: How to call an async function synchronously #8

Open
@dewoller

Description

@dewoller

Hello @ms-jpq , thanks again for the lovely code and tutorial. It is helping me slowly get my head around asynchronous programming. Can you tell me how you would call an one of your async function synchronously?

For example, using your tutorial code:

print('sync example start ')
print( async_tasks_2(1)())
print('sync example end')

prints

sync example start                                                                                                                                                                                                              
sync example end
1 2
3 4

I would like it to print

sync example start                                                                                                                                                                                                              
1 2
3 4
sync example end

:-)

Tutorials in other languages talk about blocking until the task is finished, but if I try to wait without the surrounding sync, there are issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions