mirror of
https://github.com/mailscope/kumomta.git
synced 2026-08-19 19:08:17 +00:00
42bf5c5e61
We've been hoping that mkdocs-material will ship the much anticipated search enhancements for some time, but it's time to recognize that we need to do something to improve the search results with how things work right now. This is a big commit that changes the titles of the various pages from the code-annotated synopsis to just the name of the function. This makes it much easier now to match things like `kumo.reject` directly, but `reject` remains awkward to find. I think this is the best that we can do at this time. A few functions have been annotated with the `status: deprecated` to show as deprecated in the toc/nav (shows with a little trash can next to the name).
45 lines
1.3 KiB
Markdown
45 lines
1.3 KiB
Markdown
# kumo.spawn_task
|
|
|
|
```lua
|
|
kumo.spawn_task { PARAMS }
|
|
```
|
|
|
|
{{since('2024.06.10-84e84b89')}}
|
|
|
|
!!! warning
|
|
This function should be called only from inside your
|
|
[init](../events/init.md) event handler.
|
|
|
|
This function will spawn a new thread that will trigger the specified event and
|
|
run it, allowing you to set up background tasks.
|
|
|
|
`PARAMS` is a lua table style object with the following fields:
|
|
|
|
* `event_name` - the name of the event which should be triggered in
|
|
the new thread. You must register an event handler for this event
|
|
using [kumo.on](on.md).
|
|
* `args` - an optional value that is passed to the event handler.
|
|
You can use this to pass arguments to the event handler, which is
|
|
useful in the case where you want to perform the same basic function
|
|
in a task, but with varying parameters.
|
|
|
|
```lua
|
|
kumo.on('init', function()
|
|
kumo.spawn_task {
|
|
event_name = 'my.task',
|
|
args = { 'hello', 'there' },
|
|
}
|
|
end)
|
|
|
|
kumo.on('my.task', function(args)
|
|
-- Prints: `I am the task. ["hello","there"]`
|
|
print('I am the task.', kumo.json_encode(args))
|
|
end)
|
|
```
|
|
|
|
!!! note
|
|
If your task event handler raises an error, it will be logged and
|
|
the task will stop. It is your responsibility to handle errors
|
|
to ensure that your task remains running. You can use the lua
|
|
`pcall` function to trap errors and react accordingly.
|