Last active
March 15, 2019 13:53
-
-
Save Srlion/14e0522fed904d92e5297ee3570663df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
requires: | |
async | |
https://github.com/Srlion/sr-stuff/blob/master/lua/async.lua | |
netstream | |
https://github.com/alexgrist/NetStream/blob/master/netstream2.lua | |
OR | |
https://github.com/Srlion/sr-stuff/blob/master/lua/netstream.lua | |
only works clientside mabe will add it later for serverside | |
example: -- if u are not using my version then just remove the check function | |
if SERVER then | |
local function check(ply) | |
if !ply:IsSuperAdmin() then | |
return false | |
end | |
end | |
async.netReceive("test", async(function(rs, ply, ...) | |
async.Sleep(1) | |
rs(ply, ...) -- You have to use this instead of return | |
end), check) | |
-- OR | |
async.netReceive("test", function(rs, ply, ...) | |
rs(...) | |
end, check) | |
end | |
if CLIENT then | |
local startTest = async(function(...) | |
async.Sleep(math.Rand(0, 1)) | |
local id, _nil, bool, bool2, num, str, tbl = async.netStart("test", ...) | |
print(id, _nil, bool, bool2, num, str, tbl) | |
end) | |
for i=1, 3 do | |
startTest(i, nil, false, true, 1, "string", {}) | |
end | |
end | |
]]-- | |
local async = SSM.async | |
local netstream = SSM.netstream | |
local unpack = unpack | |
local select = select | |
local isnumber = isnumber | |
local IsValid = IsValid | |
if SERVER then | |
function async.netReceive(name, fn, check) | |
netstream.Hook(name, function(ply, i, ...) | |
if (!isnumber(i)) then return end | |
local rs = function(...) | |
if !IsValid(ply) then return end | |
netstream.Start(ply, name, i, ...) | |
end | |
fn(rs, ply, ...) | |
end, check) | |
end | |
else | |
local receivers = {} | |
function async.netStart(name, ...) | |
local len = #receivers + 1 | |
netstream.Hook(name, function(i, ...) | |
receivers[i](...) | |
receivers[i] = nil | |
end) | |
netstream.Start(name, len, ...) | |
return async.Promise(function(rs) | |
receivers[len] = rs | |
end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment