Skip to content

Commit

Permalink
Clarify functions for jobs must be defined when worker is started (#53)
Browse files Browse the repository at this point in the history
* Clarify functions for jobs must be defined when worker is started

Per discussion in #17

* Clarify before vs when

Co-authored-by: Mathias Fredriksson <[email protected]>

* Clarify before vs when

Co-authored-by: Mathias Fredriksson <[email protected]>

* Comment clarification for async_job(): function must be defined before worker created

Per #17

Co-authored-by: Mathias Fredriksson <[email protected]>
  • Loading branch information
von and mafredri committed Mar 3, 2021
1 parent 0f3b27b commit a61239d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ This library bridges the gap between spawning child processes and disowning them

The async worker is a separate environment (think web worker). You send it a job (command + parameters) to execute and it returns the result of that execution through a callback function. If you find that you need to stop/start a worker to update global state (variables) you should consider refactoring so that state is passed during the `async_job` call (e.g. `async_job my_worker my_function $state1 $state2`).

Note that because the worker is a separate forked environment, any functions you want to use as jobs in the worker need to be defined before the worker is started, otherwise you will get a `command not found` error when you try to launch the job.

### Installation

#### Manual
Expand Down Expand Up @@ -60,7 +62,7 @@ Simply stops a worker and all active jobs will be terminated immediately.

#### `async_job <worker_name> <my_function> [<function_params>]`

Start a new asynchronous job on specified worker, assumes the worker is running.
Start a new asynchronous job on specified worker, assumes the worker is running. Note if you are using a function for the job, it must have been defined before the worker was started or you will get a `command not found` error.

#### `async_worker_eval <worker_name> <my_function> [<function_params>]`

Expand Down
3 changes: 3 additions & 0 deletions async.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ _async_send_job() {
#
# Start a new asynchronous job on specified worker, assumes the worker is running.
#
# Note if you are using a function for the job, it must have been defined before the worker was
# started or you will get a `command not found` error.
#
# usage:
# async_job <worker_name> <my_function> [<function_params>]
#
Expand Down

0 comments on commit a61239d

Please sign in to comment.