As the title says. I’m currently working on extremely rapid multithreading which needs to be able to send and receive data multiple times a frame. I’ve tried most of the methods but I’m not quite sure which is the fastest. What do you think?
Well, in terms of speed you could set-up a bindable event (or two) to transfer information between threads, and clean it up after it’s done. I wrote a module that allows you to create them with ease:
--[=[
Creates a bindable event and passes the parameters passed (as types) to the function parameters.
The table returned has four methods:
Connect, Yield, Fire, Destroy
Example :
local Signal = require(game:GetService("ReplicatedStorage").Signal)
local NewSignal = Signal.new("",0,"")
local Connect = NewSignal:Connect(function(A,B,C)
--// A would show up as "string" in the type-checker, B would be "number", C would also be "string"
end)
NewSignal:Fire("Variable1",10,"Variable2") --// The parameters would automatically be filled here. (string,number,string) .. etc etc.
]=]
--// Type Casting
type returnFunc<tuple...> = (tuple...) -> any
export type Signal<X...> = {
Connect : ((self : Signal<X...>, returnFunc<X...>) -> RBXScriptConnection);
Wait : ((self : Signal<X...>, returnFunc<X...>?) -> X...);
Fire : ((self : Signal<X...>, X...) -> never);
Destroy : ((self : Signal<X...>) -> never);
}
-- // Event Class
local Event = {}
Event.__index = Event
function Event.new<T...>(... : T...) : Signal<T...>
local tb = {}
tb.Event = Instance.new("BindableEvent")
tb.Signal = tb.Event.Event
--// type casted functions
tb.Connect = function(self, callback)
assert(callback, "callback must be specified!")
return self.Signal:Connect(callback)
end
tb.Wait = function(self, callback)
local value = self.Signal:Wait()
return if (type(callback) == "function") then callback(value) else value
end
tb.Fire = function(self, ...)
self.Event:Fire(...)
end
tb.Destroy = function(self)
if self.Event then self.Event:Destroy(); end
setmetatable(self,nil)
end
return setmetatable(tb,Event)
end
function Event.New<T...>(... : T...) : Signal<T...>
return Event.new(...)
end
return Event
Tell me how that goes! I am pretty curious to see what kind of methods you’ve tried.