File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -698,6 +698,25 @@ def readonly?
698698 @readonly
699699 end
700700
701+ # Sets a #busy_handler that releases the GVL between retries,
702+ # but only retries up to the indicated number of +milliseconds+.
703+ # This is an alternative to #busy_timeout, which holds the GVL
704+ # while SQLite sleeps and retries.
705+ def busy_handler_timeout = ( milliseconds )
706+ timeout_seconds = milliseconds . fdiv ( 1000 )
707+
708+ busy_handler do |count |
709+ now = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
710+ if count . zero?
711+ @timeout_deadline = now + timeout_seconds
712+ elsif now > @timeout_deadline
713+ next false
714+ else
715+ sleep ( 0.001 )
716+ end
717+ end
718+ end
719+
701720 # A helper class for dealing with custom functions (see #create_function,
702721 # #create_aggregate, and #create_aggregate_handler). It encapsulates the
703722 # opaque function object that represents the current invocation. It also
You can’t perform that action at this time.
0 commit comments