Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Fix remove all listeners in Electron v3 #19275

Merged
merged 2 commits into from May 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/task.coffee
Expand Up @@ -84,17 +84,23 @@ class Task

# Routes messages from the child to the appropriate event.
handleEvents: ->
@childProcess.removeAllListeners()
# TodoElectronIssue: removeAllListeners() without arguments does not work on electron v3.
# Remove the argument when migrating to electron v4.
@childProcess.removeAllListeners('message')
@childProcess.on 'message', ({event, args}) =>
@emitter.emit(event, args) if @childProcess?

# Catch the errors that happened before task-bootstrap.
if @childProcess.stdout?
@childProcess.stdout.removeAllListeners()
# TodoElectronIssue: removeAllListeners() without arguments does not work on electron v3.
# Remove the argument when migrating to electron v4.
@childProcess.stdout.removeAllListeners('data')
@childProcess.stdout.on 'data', (data) -> console.log data.toString()

if @childProcess.stderr?
@childProcess.stderr.removeAllListeners()
# TodoElectronIssue: removeAllListeners() without arguments does not work on electron v3.
# Remove the argument when migrating to electron v4.
@childProcess.stderr.removeAllListeners('data')
@childProcess.stderr.on 'data', (data) -> console.error data.toString()

# Public: Starts the task.
Expand Down Expand Up @@ -147,9 +153,11 @@ class Task
terminate: ->
return false unless @childProcess?

@childProcess.removeAllListeners()
@childProcess.stdout?.removeAllListeners()
@childProcess.stderr?.removeAllListeners()
# TodoElectronIssue: removeAllListeners() without arguments does not work on electron v3.
# Remove the argument when migrating to electron v4.
@childProcess.removeAllListeners('message')
@childProcess.stdout?.removeAllListeners('data')
@childProcess.stderr?.removeAllListeners('data')
@childProcess.kill()
@childProcess = null

Expand Down