Skip to content

Commit

Permalink
docs: add more details about ya.sync() and its usage
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Feb 19, 2024
1 parent 9cd0e17 commit 0db1b41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion docs/plugins/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ You can also obtain a small amount of app data from the sync context by calling

```lua
-- ~/.config/yazi/plugins/my-async-plugin.yazi/init.lua

local get_hovered_url = ya.sync(function(a, b)
-- You can access all app data through the `cx`,
-- within the `sync()` block, in an async plugin
Expand All @@ -138,6 +137,18 @@ return {
}
```

Note that `ya.sync()` call must be at the top level, and do not use it in sync plugins, as these are undefined behaviors that may lead to unexpected results:

```lua
-- Wrong !!!
local get_hovered_url
if some_condition then
get_hovered_url = ya.sync(function(a, b)
-- ...
end)
end
```

## Interface

### Previewer
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Append messages to [the log file](./overview.md#logging) at the error level:

### `sync(fn)`

TODO
See [Async context](/docs/plugins/overview.md#async-context).

### `preview_code(opts)`

Expand Down

0 comments on commit 0db1b41

Please sign in to comment.