nirish

config files for niri window manager
Log | Files | Refs | README | LICENSE

parse-state.lua (936B)


      1 
      2 local msg = require 'mp.msg'
      3 
      4 local g = require 'modules.globals'
      5 
      6 ---@class ParseStateAPI
      7 local parse_state_API = {}
      8 
      9 ---A wrapper around coroutine.yield that aborts the coroutine if
     10 --the parse request was cancelled by the user.
     11 --the coroutine is
     12 ---@async
     13 ---@param self ParseState
     14 ---@param ... any
     15 ---@return unknown ...
     16 function parse_state_API:yield(...)
     17     local co = coroutine.running()
     18     local is_browser = co == g.state.co
     19 
     20     local result = table.pack(coroutine.yield(...))
     21     if is_browser and co ~= g.state.co then
     22         msg.verbose("browser no longer waiting for list - aborting parse for", self.directory)
     23         error(g.ABORT_ERROR)
     24     end
     25     return table.unpack(result, 1, result.n)
     26 end
     27 
     28 ---Checks if the current coroutine is the one handling the browser's request.
     29 ---@return boolean
     30 function parse_state_API:is_coroutine_current()
     31     return coroutine.running() == g.state.co
     32 end
     33 
     34 return parse_state_API