I was just making a RemoteEvent, when I noticed that the Event has the functions :ConnectParallel()
and :Once()
and I wonder what they do. They don’t have a documentation in the wiki. I checked the DevForum and there are not much posts about them. I read the posts and I still don’t understand. So I’m asking in this website instead. Thank you!
Because you did not understand the Forum, i am going to try and make this as descriptive as i can. It may cause that there is a lot of information you already know.
I am also referring to CPU Cores but with that mean threads. (To make it simpler)
:Once()
Basically :Connect() but it detaches itself automatically after the first call. Means: It runs the connected function once and then never again until you reconnect it.
ConnectParallel()
First you need to understand that a CPU Core can only do one thing at a time. Meaning: Your CPU can only run 1 script at a time. If we wanted to run multiple things at a time (to speed up certain processes), we can do either task.desynchronize() or :ConnectParallel() which basically uses more CPU cores.
To use the function 2 things must be true:
The scripts must be parented under different Actor instances
The thread within a script must be desynchronized either via task.desynchronize() or Signal::ConnectParallel
(If you know what task.desynchronize() is, then :ConnectParallel() is basically the same but more efficient than using :Connect() + task.desynchronize(). )
If you ever worked with coroutines, you know that multiple lines of code can run at the same time. Coroutine works on one core still though and is synchronized with all other tasks because of that (it runs the same speed with other tasks).
Now if you are running something unsynchronized, it runs on a different CPU Core and may be faster or slower depending on Workload. This introduces a bunch of Problems as you may need to yield Code to wait for everything to be there and not miss information.
Do not just Slap :ConnectParallel() everywhere, as it may either decrease performance or cause a lot of Errors. If used correctly though, it may speed up things significantly!
Basically think of it as a Team: One Person can do one task at a time with little errors. If you spread the Workload onto a Team, it is done faster but introduces more errors because people do not exactly know what to do exactly or how to do it. There is more communication needed.
I hope this helped a bit! If you do not understand it, stick to :Connect() and coroutines as it may introduce many complicated Errors or slow down code.