From 430376e07735369207850eb465903c529a249df6 Mon Sep 17 00:00:00 2001 From: danielefongo Date: Wed, 10 Apr 2024 22:17:55 +0200 Subject: [PATCH] refactor(api.command): move read_start into spawn --- lua/microscope/api/command.lua | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lua/microscope/api/command.lua b/lua/microscope/api/command.lua index 2c13fa0..4606c08 100644 --- a/lua/microscope/api/command.lua +++ b/lua/microscope/api/command.lua @@ -39,6 +39,14 @@ function command:spawn(last) }, function() self:close() end) + + if last then + uv.read_start(self.output_stream, function(_, data) + if data then + self.output = self.output .. data + end + end) + end else local previous_output = function() end if self.input then @@ -69,18 +77,6 @@ function command:spawn(last) end end -function command:read_start() - if self.input then - self.input:read_start() - end - - uv.read_start(self.output_stream, function(_, data) - if data then - self.output = self.output .. data - end - end) -end - function command:get_consumer() return function() if self.handle and self.handle:is_active() and not self.output:find("\n") then @@ -97,7 +93,6 @@ end function command:get_iter() self:spawn(true) - self:read_start() return self:get_consumer() end