BindToMessageParallel needs to disconnect?

I am using parallel processing to speed up processing of my game data.
This requires repeated uses of :SendMessage() and :BindToMessage(). But it seems that each time I use :SendMessage() it stacks and repeats the return message. As if I were constantly using :Connect() (which results in one event firing multiple functions, similar to what happens in my code)


In the deferred threads section, you see 8 green lines that correspond to a message being returned.

But here there are many more returns!
It seems that each time a message is sent, it returns the total amount of messages sent.

I.e.
send two messages, return two
send another two messages, return four

But when printing out each time a message is returned, it still just prints the two messages sent.
image

I am wondering if there is a way to disconnect(?) and prevent so many return messages from being sent.

image
Script Code:

debug.profilebegin("Send Messages")
	local Messages=0
	for i,column in pairs(ToUnzip) do
		for o,chunk in pairs(column) do
			Messages+=1
			Actors[CurrentActor]:SendMessage("Unzip",world[i][o],i,o)

			CurrentActor+=1
			if CurrentActor>#Actors then
				CurrentActor=1
			end
		end
	end
	print(Messages)
	debug.profileend()
	
	local MessageReturns=0
	script.Parent:BindToMessage("ReturningChunk",function(Chunk,posX,posZ,num)
		debug.profilebegin("SettingChunk")
		MessageReturns+=1
		if not Unzipped[posX] then
			Unzipped[posX]={}
		end
		Unzipped[posX][posZ]=Chunk
		debug.profileend()
	end)
	task.wait()
	print(MessageReturns)

Actors Code:

local http=game:GetService("HttpService")
script.Parent:BindToMessageParallel("Unzip",function(Chunk,PositionX,PositionZ)
	local UnzippedChunk=http:JSONDecode(Chunk)
	game.ServerScriptService.Actor:SendMessage("ReturningChunk",UnzippedChunk,PositionX,PositionZ)
end)

This problem is exactly as expected. I am in fact connecting multiple functions (I guess in this case it would be binding as connecting uses :Connect()) to the same message, simply moving the BindToMessage Section out of the function works:

script.Parent:BindToMessage("ReturningChunk",function(Chunk,posX,posZ,num)
	debug.profilebegin("SettingChunk")
	MessageReturns+=1
	if not Unzipped[posX] then
		Unzipped[posX]={}
	end
	Unzipped[posX][posZ]=Chunk
	debug.profileend()
end)

game.ReplicatedStorage.GetChunks.OnServerInvoke = function(Player,ChunksWanted)

	--...
	
	debug.profilebegin("Send Messages")
	local Messages=0
	for i,column in pairs(ToUnzip) do
		for o,chunk in pairs(column) do
			Messages+=1
			Actors[CurrentActor]:SendMessage("Unzip",world[i][o],i,o)

			CurrentActor+=1
			if CurrentActor>#Actors then
				CurrentActor=1
			end
		end
	end
	print(Messages)
	debug.profileend()
	
	MessageReturns=0
	--Wait for BindToMessage function above
	task.wait()
	print(MessageReturns)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.