From 7be520be388042196f88407010fc05a089fb0119 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sun, 31 Mar 2024 02:17:58 +0800 Subject: [PATCH] docs: add sync context note to ps API --- docs/plugins/utils.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/plugins/utils.md b/docs/plugins/utils.md index 019e2794..d5f10bec 100644 --- a/docs/plugins/utils.md +++ b/docs/plugins/utils.md @@ -310,6 +310,8 @@ Only available on Unix-like systems. Returns the hostname of the current machine Yazi's DDS (Data Distribution Service) uses a Lua-based publish-subscribe model as its carrier. That is, you can achieve cross-instance communication and state persistence through the `ps` API. +The following functions can only be used within a sync context. + ### `pub(kind, value)` {#ps.pub} ```lua @@ -367,7 +369,7 @@ Subscribe to local messages of `kind` and call the `callback` handler for it: - `kind` - Required, the kind of the message, which is a string - `callback` - Required, the callback function, with a single parameter `body` containing the content of the message -which runs in a synchronous context, so you can access app data via `cx` for the content of interest. +which runs in a sync context, so you can access app data via `cx` for the content of interest. Note: No time-consuming operations should be done in the callback, and the same `kind` from the same plugin can only be subscribed once, re-subscribing (`sub()`) before unsubscribing (`unsub()`) will throw an error.