Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
oneSignal.luau minor improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
imezx committed Oct 21, 2023
1 parent 298add1 commit b048575
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/oneSignal.luau
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
-- (https://github.com/imezx/oneSignal/blob/main/oneSignal.luau)

local oneSignal = {}
oneSignal.ClassName = "oneSignal"
oneSignal.ClassName = "Signal"
oneSignal.__index = oneSignal

local HttpService = game:GetService("HttpService")
local Collections = {}

local FastSpawn = require(script.Parent.FastSpawn)
local Debug = require(script.Parent.Debug)

function oneSignal.new(identifier: string)
Expand Down Expand Up @@ -46,18 +46,16 @@ function oneSignal:Invoke(timeout: number, ...: any): any
task.spawn(thread, nil)
packed = nil
end)
retrive = task.spawn(function()
task.wait(1/60)
task.cancel(session)
retrive = task.defer(function()
task.spawn(thread, self.cb(table.unpack(packed)))
task.cancel(session)
packed = nil
end)
return coroutine.yield()
end

function oneSignal:Wait(): number
local thread = coroutine.running()
local clock = os.clock()
local thread, clock = coroutine.running(), os.clock()
self._ping = function(x)
self._ping = nil
task.spawn(thread, (x - clock))
Expand All @@ -67,10 +65,9 @@ end

function oneSignal:Once(callback: (...any) -> ())
if not self.Connected then
self.cb = function(...)
self:Connect(function()
self:Disconnect()
task.spawn(callback, ...)
end
end)
self.Connected = true
end
end
Expand All @@ -85,15 +82,15 @@ end
function oneSignal:Destroy()
self:Disconnect()
Collections[self.Identifier] = nil
self = nil
setmetatable(self, nil)
end

function oneSignal:Fire(...: any)
if self.Connected then
task.spawn(self.cb, ...)
FastSpawn(self.cb, ...)
end
if self._ping then
task.spawn(self._ping, os.clock())
FastSpawn(self._ping, os.clock())
end
end

Expand Down

0 comments on commit b048575

Please sign in to comment.