#Suphi's Signal Module

1 messages · Page 1 of 1 (latest)

patent harness
#

Suphi's Signal Module

#

Features

No Parameter Limitations                   Unlike ROBLOX Events there are no parameter limitations
Store Values Inside The Connection         Pass values when connecting a function to be passed to the fuction
Table Reference                            Passing a table will pass a refrence and does not deep clone the table
Fire In Order                              Events are fired in the same order they where connected in
Does not relay on workspace.SignalBehavior Always spawns signals even if signal behavior is set to deferred
Familiar                                   Works a lot like RBXScriptSignal and RBXScriptConnection
#

BENCHMARKS

            | FastSignal | SuphisSignal | GoodSignal | SimpleSignal | RobloxSignal |
------------------------------------------------------------------------------------
New         |  0.2       |  ?           |  0.2       |  0.1         |  1.1         |
Connect     |  0.5       |  ?           |  0.4       |  0.3         |  2.3         |
Disconnect  |  0.1       |  ?           |  139.8     |  3.8         |  39.0        |
Fire        |  2.0       |  ? & ?       |  31.3      |  104.9       |  30.6        |
Wait        |  3.5       |  ?           |  3.9       |  5.3         |  5.4         |

DOWNLOAD BENCHMARK
#1042810934277713931 message

microseconds to complete (lower is better)
Fire is the most important benchmark as that's what your going to be doing the most

#

SuphisSignal vs FastSignal

FastSignal does not create new threads when it fires connections this makes FastSignal fast but if any of the connections use async functions or have task.wait() it will block the next connections from fireing until the current connection has finished SuphisSignal has a method called FastFire that works like FastSignal

SuphisSignal vs GoodSignal

SuphisSignal works a lot like GoodSignal but with some small differences
1) GoodSignal only caches 1 thread where SuphisSignal caches 16 threads it creates
2) GoodSignal and SuphisSignal both use linked lists but SuphisSignal uses doubly linked list this allows SuphisSignal to disconnect connections without traversing the list
3) GoodSignal new connections are added to the front of the list making connections fire in reverse order SuphisSignal adds new connections to the end of the list making them fire in the same order as they where connected
#

SIGNAL MODULE
CONSTRUCTORS

new()  signal
Returns a new signal object
#

SIGNAL OBJECT
PROPERTIES

Connections  number  0  READ ONLY
The amount of connections connected to this signal

EVENTS

Connected(connected: boolean, signal: Signal)  nil
Fires when the signal gets its first connection or if it removes its last connection 

METHODS

Connect(func: function, arguments...: tuple)  connection
Connects the given function to the event and returns an connection that represents it
``````ansi
Once(func: function, arguments...: tuple)  connection
Connects the given function to the event (for a single invocation) and returns an connection that represents it
``````ansi
Wait(arguments...: tuple)  tuple
Yields the current thread until the signal fires and returns the arguments provided by the signal
``````ansi
Fire(arguments...: tuple)  nil
Fires the event
``````ansi
FastFire(arguments...: tuple)  nil
Fires the event without creating threads
``````ansi
DisconnectAll()  nil
Disconnects all connections from the signal
#

CONNECTION OBJECT
PROPERTIES

Signal  signal?  Signal  READ ONLY
The signal object this connection is connected to or nil

METHODS

Disconnect()  nil
Disconnects the connection from the signal
#

SIMPLE EXAMPLE

-- Require the ModuleScript
local signalModule = require(11670710927)

-- create a signal object
local signal = signalModule.new()

-- connect a function to the signal
local connection = signal:Connect(function(...)
  print(...)
end)

-- fire the signal
signal:Fire("Hello world!")

-- Disconnect the connection from the signal
connection:Disconnect()
#

DISCONNECT ALL EXAMPLE


local signalModule = require(11670710927)
local signal = signalModule.new()
signal:Connect(function(...) print("Conection1", ...) end)
signal:Connect(function(...) print("Conection2", ...) end)
signal:Connect(function(...) print("Conection3", ...) end)

signal:Fire("Hello world!")

-- Disconnect all connections from the signal
signal:DisconnectAll()

-- fire the signal again this time nothing will print to output because we disconnected all connections
signal:Fire("Hello world!")
#

ONCE EXAMPLE


local signalModule = require(11670710927)
local signal = signalModule.new()

-- connection a function to only be called once
signal:Once(function(...) print(...) end)

signal:Fire("Hello world!")

-- fire the signal again this time nothing will print to output because once will automatically disconnect once it gets fired
signal:Fire("Hello world!")
#

WAIT EXAMPLE

local signalModule = require(11670710927)
local signal = signalModule.new()

-- fire after a 10 second delay
task.delay(10, signal.Fire, signal, "Hello world!")

-- wait for the signal to fire then print it
print(signal:Wait())
#

ARGUMENTS EXAMPLE

local function Event(...)
  print(...) -- Hello World Goodbye 69
end

local signalModule = require(11670710927)
local signal = signalModule.new()
signal:Connect(Event, "Goodbye", 69) -- connect to the signal and save the values Goodbye and 69 into the connection
signal:Fire("Hello", "World")
#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

#

_ _

patent harness
patent harness
#
version 0.5 is now out
you can now pass custom arguments into Connect, Once and Wait that will be past to the function when called
patent harness
#

Suphi's Signal Module

#
version 1.0 is now out
added Connections property
added Connected callback to detect when the signal gets connections
improved proxy
under the hood changes
fierce dust
daring robin
#

Do signals automatically garbage collect, or do we have to manually gc them

#

Once all references to the explosion are gone, is it the same for the signal?

patent harness
daring robin
#

Got it, thanks

mystic cape
#

This is peak

scarlet pivot
#

@patent harness sorry for the ping, is this faster than fastsignal? Im on mobile and the formatting is really bad.

patent harness
#

no

#

its slower then fast signal and good signal

#

but only a small difference then good signal

jaunty inlet
#

One message removed from a suspended account.

patent harness
#

my module was not designed to be fast it was designed to be safe

#

so that people could not break the datastore module

jaunty inlet
#

One message removed from a suspended account.

patent harness
#

but i have a fast signal module i use in my own games but its not safe

jaunty inlet
#

One message removed from a suspended account.

patent harness
#

it does not use the standered connection class

jaunty inlet
#

One message removed from a suspended account.

patent harness
#

Because it does not create new threads

jaunty inlet
#

Compared to LemonSignal, does this outperform it?

patent harness
#

when creating this module it was not designed to be fast but to work well with SDM and to be sandboxed

patent harness
brittle gale
waxen tundra
#

I do got one that outperforms LemonSignal and Suphi's while still being determinstic

#

This was comparison I just tried

#

This got 1000 connections lol

#

Buh just one I wrote myself

#

But Suphi's is very good but not deterministic if that is important

#

And then Suphi's

#

I switched my signal from task.spawn to task.defer here to match Suphi's

#

But mine fires in determined order since using a linked list

#

But all are good :D

waxen tundra
#

I just changed mine now but idk if there issue but everything I've tested works fine

patent harness
waxen tundra
#

Yeah I compared to GF one

#

Also what is difference between coroutine.resume() and task.spawn()

#

So if I got

#

this for threads would calling it with coroutine.resume() have different outcome than task.spawn()

daring robin
#

@patent harness I've been using this module recently for my projects (Love it, thx). I'm trying to better understand thread manipulation so I've been looking at it's source a bit more and was wondering what this block of code does (Lines 96 to 100).

From what it looks like I know its for removing a connection and resetting the linked list's start and tail, but what does that very last line really mean, mainly the task.defer part.

if signal.__public.Connections == 0 and signal.__public.Connected ~= nil then task.defer(signal.__public.Connected, false, proxy) end
#

Cause I dont see any threads or functions named connected

patent harness
waxen tundra
#

Have you tried other signal modules?

daring robin
#

Ima play around with the code of this one and see of and where that line originates from

weary anchor
#

aso what about the benchmarks

#

also*