Skip to content

[FEATURE]: Do you consider adding plenary.job like feature in a nio way? #5

@pysan3

Description

@pysan3

Ref: plenary.job.

As title. It'd be awesome if it could be implemented without using callbacks.

EDIT: New API

Ref: #7

 local first = nio.process.run({
   cmd = "printf", args = { "hello" }
 })

 local second = nio.process.run({
   cmd = "cat", stdin = first.stdout
 })

 local output = second.stdout.read()
 print(output)

OLD

-- Just my random thoughts.

nio.run(function()
  local job = nio.job.new("echo foo; echo bar; echo baz 1>&2")
  local iter = job:start()
  for line in iter do
    if line.type == "stdout" then
      on_stdout(line.content)
    elseif line.type == "stderr" then
      on_stderr(line.content)
    elseif line.type == "exit" then
      on_exit(line.exit_stat --[[@as integer]])
    end
  end
end)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions