3 ms·
This is weird to me: "A method is called asynchronously when the return value is not used." Which means the behavior changes when there is no return value?
by sigmonsays 2y ago
This is weird to me:
"A method is called asynchronously when the return value is not used."
Which means the behavior changes when there is no return value?
- kll 2y agoYes, it does affect the local control flow. If you don't assign the return value, then the local actor will proceed execution of the next thing, so effectively async execution of the remote method call. You can also write this explicitly like so: async remote_actor.foobar() If you on the other hand want to wait for that remote actor to finish but still not assign locally you can use a dummy variable: _ = remote_actor.foobar() or explicitly ask to await await async remote_actor.foobar() You can also explicitly ask for async while grabbing the return value, which makes it easy to run things concurrently a1 = async remote_actor1.foobar() a2 = async remote_actor2.foobar() print("a1 and a2 run concurrently") r1 = await a1 # collect both results r2 = await a2 print(r1, r2)
- pepa65 2y agoReturn value is not needed, so just "call away" -- asynchronously. I guess this means when a return value is used, the call is synchronous, and after running the method processing resumes where things left off.
- kll 2y agoYes indeed, assigning really turns into an await on an async value. You can explicitly write it as a = await async remote_actor.foobar() So the local actor goes to sleep, awaiting the remote, then the RTS notices the returned value and place the actor on the readyQ for execution, thus waking up from the await.