Run a node script in a separate process.
Used by the fuzzy-finder and find in project.
For a real-world example, see the scan-handler and the instantiation of the task.
In your package code:
[Task](../Task/) = require 'atom'
task = Task.once '/path/to/task-file.coffee', parameter1, parameter2, ->
console.log 'task has finished'
task.on 'some-event-from-the-task', (data) =>
console.log data.someString # prints 'yep this is it'
In '/path/to/task-file.coffee'
:
module.exports = (parameter1, parameter2) ->
# Indicates that this task will be async.
# Call the `callback` to finish the task
callback = @async()
emit('some-event-from-the-task', {someString: 'yep this is it'})
callback()
Starts the task.
Throws an error if this task has already been terminated or if sending a message to the child process fails.
Argument | Description |
---|---|
|
The arguments to pass to the function exported by this task’s script. |
|
optional
A Function to call when the task completes. |
Send message to the task.
Throws an error if this task has already been terminated or if sending a message to the child process fails.
Argument | Description |
---|---|
|
The message to send to the task. |
Call a function when an event is emitted by the child process
Argument | Description |
---|---|
|
The String name of the event to handle. |
|
The Function to call when the event is emitted. |
Return values |
---|
Returns a Disposable that can be used to stop listening for the event. |
Forcefully stop the running task.
No more events are emitted once this method is called.
Cancel the running task and emit an event if it was canceled.
Return values |
---|
Returns a Boolean indicating whether the task was terminated. |