Skip to content

ChildProcess needs to be an EventEmitter #17

Closed
@pcraddick

Description

@pcraddick

Big Kudos to you for undertaking this ambitious project -- I'm quite excited about the possibilities.

While taking things for a test drive, I discovered that I wasn't able to get IPC working between child and parent processes - owing to the current definition of ChildProcess.scala.

( For context note this : "Each of the methods returns a ChildProcess instance. These objects implement the Node.js EventEmitter API, allowing the parent process to register listener functions that are called when certain events occur during the life cycle of the child process." )

I made this change locally and built/published:

diff --git a/src/main/scala/io/scalajs/nodejs/child_process/ChildProcess.scala b/src/main/scala/io/scalajs/nodejs/child_process/ChildProcess.scala
index 5be52bf..359c3bc 100644
--- a/src/main/scala/io/scalajs/nodejs/child_process/ChildProcess.scala
+++ b/src/main/scala/io/scalajs/nodejs/child_process/ChildProcess.scala
@@ -3,6 +3,7 @@ package child_process

 import io.scalajs.RawOptions
 import io.scalajs.nodejs.buffer.Buffer
+import io.scalajs.nodejs.events.IEventEmitter

 import scala.scalajs.js
 import scala.scalajs.js.annotation.JSImport
@@ -15,7 +16,7 @@ import scala.scalajs.js.|
   * @author lawrence.daniels@gmail.com
   */
 @js.native
-trait ChildProcess extends js.Object {
+trait ChildProcess extends js.Object with IEventEmitter {

... and this now works:

import io.scalajs.nodejs.child_process.ChildProcess    
val p = ChildProcess.fork("./test.js")
p.on("message", (message: String) => {
  println("Message", message)
})

If you want me to submit a PR, please grant me access to the repo.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions