Class: Dommy::LockManager
- Inherits:
-
Object
- Object
- Dommy::LockManager
- Defined in:
- lib/dommy/navigator.rb
Overview
‘navigator.locks` — Web Locks API. Locks are scoped to the Navigator instance; serial execution per name. Real browsers coordinate across tabs; dommy is single-process so it just serializes calls within the same Window.
Spec: w3c.github.io/web-locks/
Instance Method Summary collapse
- #__js_call__(method, args) ⇒ Object
-
#initialize(window) ⇒ LockManager
constructor
A new instance of LockManager.
- #query ⇒ Object
- #request(name, options_or_callback, callback = nil) ⇒ Object
Constructor Details
#initialize(window) ⇒ LockManager
Returns a new instance of LockManager.
533 534 535 536 |
# File 'lib/dommy/navigator.rb', line 533 def initialize(window) @window = window @held = {} end |
Instance Method Details
#__js_call__(method, args) ⇒ Object
564 565 566 567 568 569 570 571 |
# File 'lib/dommy/navigator.rb', line 564 def __js_call__(method, args) case method when "request" request(args[0], args[1], args[2]) when "query" query end end |
#query ⇒ Object
559 560 561 562 |
# File 'lib/dommy/navigator.rb', line 559 def query held = @held.map { |name, lock| {"name" => name, "mode" => lock.mode, "clientId" => "dommy"} } PromiseValue.resolve(@window, {"held" => held, "pending" => []}) end |
#request(name, options_or_callback, callback = nil) ⇒ Object
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
# File 'lib/dommy/navigator.rb', line 538 def request(name, , callback = nil) if .is_a?(Hash) || .nil? = || {} cb = callback else = {} cb = end key = name.to_s if @held[key] && ["ifAvailable"] return invoke_with_lock(cb, nil) end lock = Lock.new(key, ["mode"] || "exclusive") @held[key] = lock result = invoke_with_lock(cb, lock) @held.delete(key) result end |