-- Signal class

local Signal = {}
Signal.__index = Signal

export type ClassType = typeof(setmetatable({} :: {
	_handlerListHead: SignalConnection?,
}, Signal))

function Signal.new(): ClassType
	return setmetatable({
		_handlerListHead = nil,
	}, Signal)
end

function Signal.Connect(self: ClassType, fn: Callback): SignalConnection
	local connection = Connection.new(self, fn)
	if self._handlerListHead then
		connection._next = self._handlerListHead :: SignalConnection

		self._handlerListHead = connection
	else
		self._handlerListHead = connection
	end
	return connection
end
