local O={}function O.Disconnect(O)local U=O._listener if U~=nil then local m=O._listener_table local Z=table.find(m,U)if Z~=nil then table.remove(m,Z)end O._listener=nil end if O._disconnect_listener~=nil then if not FreeRunnerThread then FreeRunnerThread=coroutine.create(RunEventHandlerInFreeThread)end task.spawn(FreeRunnerThread,O._disconnect_listener,O._disconnect_param)O._disconnect_listener=nil end end function MadworkScriptSignal.NewArrayScriptConnection(U,m,Z,v)return{_listener=m;_listener_table=U,_disconnect_listener=Z,_disconnect_param=v;Disconnect=O.Disconnect}end


local ArrayScriptConnection = {
	--[[
		_listener = function -- [function]
		_listener_table = {} -- [table] -- Table from which the function entry will be removed
		_disconnect_listener -- [function / nil]
		_disconnect_param    -- [value / nil]
	--]]
}

function ArrayScriptConnection:Disconnect()
	local listener = self._listener
	if listener ~= nil then
		local listener_table = self._listener_table
		local index = table.find(listener_table, listener)
		if index ~= nil then
			table.remove(listener_table, index)
		end
		self._listener = nil
	end
	if self._disconnect_listener ~= nil then
		if not FreeRunnerThread then
			FreeRunnerThread = coroutine.create(RunEventHandlerInFreeThread)
		end
		task.spawn(FreeRunnerThread, self._disconnect_listener, self._disconnect_param)
		self._disconnect_listener = nil
	end
end

function MadworkScriptSignal.NewArrayScriptConnection(listener_table, listener, disconnect_listener, disconnect_param) --> [ScriptConnection]
	return {
		_listener = listener,
		_listener_table = listener_table,
		_disconnect_listener = disconnect_listener,
		_disconnect_param = disconnect_param,
		Disconnect = ArrayScriptConnection.Disconnect
	}
end
