diff options
| author | ryukamish <[email protected]> | 2026-04-11 16:06:45 +0530 |
|---|---|---|
| committer | ryukamish <[email protected]> | 2026-04-11 16:06:45 +0530 |
| commit | 607891801fbf2051a0c9062d15a445dd238c1e1b (patch) | |
| tree | 33b8cfba2355b498addea05e385b06d46cced30f /mpv/scripts/file-browser/modules/apis/parse-state.lua | |
| parent | 6fbde2906e3bb2d4d1df23f6374d8a6a0aef870f (diff) | |
add: mako and mpv configs
Diffstat (limited to 'mpv/scripts/file-browser/modules/apis/parse-state.lua')
| -rw-r--r-- | mpv/scripts/file-browser/modules/apis/parse-state.lua | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/mpv/scripts/file-browser/modules/apis/parse-state.lua b/mpv/scripts/file-browser/modules/apis/parse-state.lua new file mode 100644 index 0000000..6db5658 --- /dev/null +++ b/mpv/scripts/file-browser/modules/apis/parse-state.lua @@ -0,0 +1,34 @@ + +local msg = require 'mp.msg' + +local g = require 'modules.globals' + +---@class ParseStateAPI +local parse_state_API = {} + +---A wrapper around coroutine.yield that aborts the coroutine if +--the parse request was cancelled by the user. +--the coroutine is +---@async +---@param self ParseState +---@param ... any +---@return unknown ... +function parse_state_API:yield(...) + local co = coroutine.running() + local is_browser = co == g.state.co + + local result = table.pack(coroutine.yield(...)) + if is_browser and co ~= g.state.co then + msg.verbose("browser no longer waiting for list - aborting parse for", self.directory) + error(g.ABORT_ERROR) + end + return table.unpack(result, 1, result.n) +end + +---Checks if the current coroutine is the one handling the browser's request. +---@return boolean +function parse_state_API:is_coroutine_current() + return coroutine.running() == g.state.co +end + +return parse_state_API |
