Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify functions for jobs must be defined when worker is started #53

Merged
merged 4 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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