Skip to content

Commit cc666d0

Browse files
committed
fence: add wait_until
1 parent 1cd7b86 commit cc666d0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/mpv/fence.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ def wait1(timeout: DEFAULT_TIMEOUT)
4545
wait(runs: 1, timeout: timeout).first
4646
end
4747

48+
def wait_until(timeout: DEFAULT_TIMEOUT, &block)
49+
start = Concurrent.monotonic_time
50+
loop do
51+
x = wait1(timeout: timeout / 10)
52+
break if block.call(x)
53+
break if (Concurrent.monotonic_time - start) >= timeout
54+
end
55+
x
56+
end
57+
4858
# Clears the calls history
4959
def clear!
5060
@mutex.synchronize do

0 commit comments

Comments
 (0)