What do the rbx luau terms “asynchronous” and “synchronous”. Mean

Title says it all what do these two “common” lua terms mean and what’s their importance in luau. Anybody care to explain? Please feel free to I couldn’t find any sources that explained them in a way I understood well

1 Like

They aren’t LuaU specific terms. You can actually use them in real life too btw

But anyways,

Synchronous means that your code will have to wait until the previous line of code finishes running

For example, if I have this code:

for i, v in … do
   -- random placeholder
end

print("Hello world!")

print("Hello world!") will have to wait until the in pairs loop finishes


and…


Asynchronous just means that your code can run even if the code before it hasn’t ran / isn’t finished running

task.desynchronize()
for i, v in … do
   -- another placeholder
end

print("Hello world!")

This will make it so that all of the code after the desynchronization can run at the same time AKA parallel

So that print statement will execute while the in pairs loop is also executing

Oh and by the way, if you want to make your code ahead async again, you can easily just call task.synchronize

Or you could use Actors which I won’t dive into here but they’re useful

1 Like

Got it that makes sense I understand the concept I am just not familiar with people using terms like “asynchronous” or synchronous to denote eg label them

And the will definitely be checking task.synchronize and asynchronize i am fimilair with actors their just not something I really use

Does task.synchronize and async only work in a script parented to an actor?

1 Like

Sorry for the late response

Nah you can use task.synchronize and task.desynchronize without an Actor

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.