diff --git a/src/kernel/ps/ProcessHandle.hx b/src/kernel/ps/ProcessHandle.hx index 99cace2..7adcadf 100644 --- a/src/kernel/ps/ProcessHandle.hx +++ b/src/kernel/ps/ProcessHandle.hx @@ -21,6 +21,8 @@ class ProcessHandle { private var closeFutureResolev: Bool -> Void; private final windowContexts: Array = []; private final cbLinks:Array = []; + private final deferFuncs:Array Void> = []; + private var hasExited: Bool = false; @:allow(kernel.ps.ProcessManager) private function new(config: HandleConfig,pid: PID) { @@ -42,12 +44,15 @@ class ProcessHandle { } public function close(success: Bool = true): Void { + this.hasExited = true; this.dispose(); - this.closeFutureResolev(success); + + EndOfLoop.endOfLoop(() ->{this.closeFutureResolev(success);}); ProcessManager.removeProcess(this.pid); } public function write(message: String): Void { + if (this.hasExited) return; if (this.config.onWrite != null){ this.config.onWrite.invoke(message); } @@ -77,6 +82,10 @@ class ProcessHandle { for (link in this.cbLinks) { link.cancel(); } + + for (func in this.deferFuncs) { + func(); + } } public function getPid(): PID { @@ -87,6 +96,10 @@ class ProcessHandle { this.cbLinks.push(link); } + public function addDeferFunc(func: Void -> Void) { + this.deferFuncs.push(func); + } + function get_args():ReadOnlyArray { return this.config.args; }