Skip to content

Commit

Permalink
[filter] exec() filter's onExit callback can return events as its output
Browse files Browse the repository at this point in the history
  • Loading branch information
pajama-coder committed Jul 6, 2024
1 parent 0b16501 commit 4bd367e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/filters/exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,24 @@ void Exec::on_process_exit(int exit_code) {
}

void Exec::check_ending() {
if (m_child_proc_exited && m_stdout_reader.ended() && m_stderr_reader.ended()) {
if (m_child_proc_exited) {
if (auto f = m_options.on_exit_f.get()) {
pjs::Value args[2], ret;
args[0].set(m_child_proc_exit_code);
int argc = 1;
if (!m_options.std_err) {
args[argc++].set(Data::make(std::move(m_stderr_reader.buffer())));
}
Filter::callback(f, argc, args, ret);
if (Filter::callback(f, argc, args, ret)) {
if (!ret.is_undefined()) {
if (!ret.is_object() || !Filter::output(ret.o())) {
Filter::error("onExit didn't return an event or Message or an array of those");
}
}
}
} else if (m_stdout_reader.ended() && m_stderr_reader.ended()) {
Filter::output(StreamEnd::make());
}
Filter::output(StreamEnd::make());
}
}

Expand Down

0 comments on commit 4bd367e

Please sign in to comment.