--- a/hglib.lua Mon Oct 17 23:27:50 2016 +0800
+++ b/hglib.lua Sun Oct 23 17:53:32 2016 +0800
-function Client:runcommand(command, input)
+function Client:runcommand_co(command)
if not self.capabilities.runcommand then
- return nil, '', 'runcommand is not supported by this command server', ''
+ return nil, 'runcommand is not supported by this command server'
self.wh:write('runcommand\n')
write_block(self.wh, unpack(command))
+ return coroutine.create(function()
+ local channel, message = read_channel(self.rh)
+ return channel, decode_i4(message)
+ elseif channel:lower() ~= channel and channel ~= 'I' and channel ~= 'L' then
+ return channel, message
+ coroutine.yield(channel, message)
+function Client:runcommand(command, input)
+ local co, err = self:runcommand_co(command)
+ if type(co) ~= 'thread' then
+ return nil, '', err, ''
input = input:sub(length + 1)
- local channel, message = read_channel(self.rh)
+ while coroutine.status(co) ~= 'dead' do
+ local status, channel, message = coroutine.resume(co)
+ return nil, '', '\nhglib: coroutine failure: ' .. channel, ''
- return decode_i4(message), o, e, d
+ return message, o, e, d
elseif channel == 'o' then
elseif channel == 'e' then