Use callbacks to enforce the order of operations that we want.
users = ["Sam","Alice","Bob"]defaddUser(username): users.push(username)defgetUsers():print(users)addUser("Jake")# This might run because addUsers() could be faster (in another region)getUsers()
Fix
We provide a function as an argument to another function.
users = ["Sam","Alice","Bob"]defaddUser(username,callback): users.push(username)callback()# Calling the function in heredefgetUsers():print(users)addUser("Jake". getUsers)# Notice we are passing in getUsers, not getUsers() as we do not want the function to run until inside addUser()# This might run because addUsers() could be faster (in another region)getUsers()