I’d like to report a situation I had recently with FastNet2 regarding the Pull function.
I needed to invoke the server in order to update the client but I was aware that the answer could possibly return as nil, so I had to add it into a loop. The problem is, the Pull function only requested it once.
-- CLIENT
function Controller:GetServerProfilePromise(Player : Player)
return Promise.new(function(resolve, reject, onCancel)
local Profile = DataEvent:Pull(5, "GetProfile", Player)
if Profile == nil then
repeat
task.wait(0.5)
Profile = DataEvent:Pull(5, "GetProfile", Player)
print(Profile)
until Profile ~= nil
end
resolve(Profile)
end)
end
-- SERVER
DataEvent:Connect(function(Player : Player, Action : string, ...)
local Args = {...}
if Action == "GetProfile" then
local Target : Player = Args[1]
if not Target then warn("Invalid Target: ", Target) return end
return Service:GetProfile(Target)
end
end
I solved it by just using a normal RemoteFunction.
If I was using it wrong, please let me know!
Also, I realized that you cannot call the same identifier in two Scripts / LocalScripts, it would error in the debug util.
I found that to be an issue for my use cases, so I did this modification on both the Client and Server modules:
-- CLIENT
function Client.new(Identifier: string)
Debug.new(typeof(Identifier) == "string", "[FastNet2]: Identifier must be string", 0)
--Debug.new(not Identifiers.find(Util.ser(Identifier)), string.format("[FastNet2]: %s already exist", Identifier), 0)
if not Identifiers.find(Util.ser(Identifier)) then
Process.reg(Util.ser(Identifier))
Collections[Util.ser(Identifier)] = setmetatable({
Identifier = Util.ser(Identifier),
func = function(...: any): (...any) end,
Connected = false,
flag = {},
}, Client)
end
return Collections[Util.ser(Identifier)]
end
-- SERVER
function Server.new(Identifier: string)
Debug.new(typeof(Identifier) == "string", "[FastNet2]: Identifier must be string", 0)
--Debug.new(not Identifiers.find(Util.ser(Identifier)), string.format("[FastNet2]: %s already exist", Identifier), 0)
if not Identifiers.find(Util.ser(Identifier)) then
Process.reg(Util.ser(Identifier))
Collections[Util.ser(Identifier)] = setmetatable({
Identifier = Util.ser(Identifier),
func = function(...: any): (...any) end,
Connected = false,
flag = {},
}, Server)
end
return Collections[Util.ser(Identifier)]
end
So now in case the identifier is already in use, it just returns it. This might not be compatible with other parts of the module but so far it has worked fine for me. I’d appreciate it if you could turn the possibility to use the same event in multiple scripts a feature!