Messaging Service Needs This Feature (If It Doesn't Have It Already)

Is there a way to determine when MessagingService:SubscribeAsync has finished processing on all servers?

My code:

local info = 0
local success, err = pcall(function()
	game:GetService("MessagingService"):PublishAsync("GetPlayer", {username = tostring(query)})
end)

if not success then
	warn("Publish error: ", err)
end

local con
con = game:GetService("MessagingService"):SubscribeAsync("GotPlayer", function(data)
	print("got the player!")
	info = data.Data.info
	con:Disconnect()
end)

-- wait for it to proccess then

return info

Technically.

If you have each server publish a notice saying they are starting to process the event, then another once it finishes, the various servers can then compare the number of servers which started vs the number of servers which finished to determine when all servers have process it.

Outside of that though, there’s really not any other way to determine it.

1 Like

I see, I’ll try that out and see if it works.
Thanks!

Messaging Service Needs This Feature (If It Doesn’t Have It Already)

I would recommend you look at the Two Generals Problem, which explains why it’s basically impossible (it’s similar conditions to the point you raise). Here’s a video by Tom Scott on it:

1 Like

I tried to implement it, but I’m having trouble understanding how to do it. Could you provide an example or guide me through it?

Is there a particular reason why you need to wait for all servers to be finished? I suspect that there will be an easier, more reliable way to do it which doesn’t rely on sending lots of Messaging Service requests.

My goal is to have the system wait until all servers have finished processing for a player, and only return if there’s no player present afterward. I tried using a timer to wait for a set period before returning, but I feel like that’s not the most reliable solution.