client: Wait for 'drained' event when sending stanzas (experimental, may help with syncing to server's logs)

Fri, 01 Jan 2016 20:45:22 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 01 Jan 2016 20:45:22 +0000
changeset 73
1c07ef6c6502
parent 72
4fde8d4a4c76
child 74
b3f2711684a7

client: Wait for 'drained' event when sending stanzas (experimental, may help with syncing to server's logs)

scansion/objects/client.lua file | annotate | diff | comparison | revisions
--- a/scansion/objects/client.lua	Fri Jan 01 20:44:44 2016 +0000
+++ b/scansion/objects/client.lua	Fri Jan 01 20:45:22 2016 +0000
@@ -73,7 +73,14 @@
 
 	sends = function (client, data)
 		local stanza =  fill_vars(client.script, assert(parse_xml((table.concat(data):gsub("\t", "  ")))));
+		local wait, done = async.waiter();
+		local function handle_drained()
+			client.stream:unhook("drained", handle_drained);
+			done();
+		end
+		client.stream:hook("drained", handle_drained);
 		client.stream:send(stanza);
+		wait();
 	end;
 
 	receives = function (client, data)

mercurial