local g={}g.__index=g function g.Disconnect(g)if g._is_connected==false then return end g._is_connected=false g._script_signal._listener_count-=1 if g._script_signal._head==g then g._script_signal._head=g._next else local h=g._script_signal._head while h~=nil and h._next~=g do h=h._next end if h~=nil then h._next=g._next end end if g._disconnect_listener~=nil then if not FreeRunnerThread then FreeRunnerThread=coroutine.create(RunEventHandlerInFreeThread)end task.spawn(FreeRunnerThread,g._disconnect_listener,g._disconnect_param)g._disconnect_listener=nil end end
-- ScriptConnection object:

local ScriptConnection = {
	--[[
		_listener = listener,
		_script_signal = script_signal,
		_disconnect_listener = disconnect_listener,
		_disconnect_param = disconnect_param,
		
		_next = next_script_connection,
		_is_connected = is_connected,
	--]]
}
ScriptConnection.__index = ScriptConnection

function ScriptConnection:Disconnect()
	if self._is_connected == false then
		return
	end

	self._is_connected = false
	self._script_signal._listener_count -= 1

	if self._script_signal._head == self then
		self._script_signal._head = self._next
	else
		local prev = self._script_signal._head
		while prev ~= nil and prev._next ~= self do
			prev = prev._next
		end
		if prev ~= nil then
			prev._next = self._next
		end
	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
