Module: WGPU::AsyncWaiter
- Defined in:
- lib/wgpu/core/async_waiter.rb,
sig/wgpu.rbs
Constant Summary collapse
- POLL_INTERVAL_SECONDS =
0.001- CALLBACK_MODE_FALLBACK =
{ allow_process_events: 2, allow_spontaneous: 3 }.freeze
Class Method Summary collapse
-
.callback_mode(instance:) ⇒ Integer
Selects the native callback delivery mode for an operation.
-
.poll_interval ⇒ Float
Returns the delay between callback progress polls.
-
.poll_interval=(seconds) ⇒ Float
Sets the delay between callback progress polls.
-
.wait(status_holder:, instance: nil, device: nil, future: nil, timeout: nil) ⇒ void
Drives native event processing until a callback completes.
Class Method Details
.callback_mode(instance:) ⇒ Integer
Selects the native callback delivery mode for an operation.
34 35 36 37 38 39 40 |
# File 'lib/wgpu/core/async_waiter.rb', line 34 def callback_mode(instance:) if instance callback_mode_value(:allow_process_events) else callback_mode_value(:allow_spontaneous) end end |
.poll_interval ⇒ Float
Returns the delay between callback progress polls.
15 16 17 |
# File 'lib/wgpu/core/async_waiter.rb', line 15 def poll_interval @poll_interval ||= POLL_INTERVAL_SECONDS end |
.poll_interval=(seconds) ⇒ Float
Sets the delay between callback progress polls.
23 24 25 26 27 28 |
# File 'lib/wgpu/core/async_waiter.rb', line 23 def poll_interval=(seconds) value = Float(seconds) raise ArgumentError, "poll interval must be positive" unless value.positive? @poll_interval = value end |
.wait(status_holder:, instance: nil, device: nil, future: nil, timeout: nil) ⇒ void
This method returns an undefined value.
Drives native event processing until a callback completes.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/wgpu/core/async_waiter.rb', line 47 def wait(status_holder:, instance: nil, device: nil, future: nil, timeout: nil) timeout = Float(timeout) if timeout raise ArgumentError, "timeout must be non-negative" if timeout&.negative? deadline = monotonic_time + timeout if timeout wait_info = build_wait_info(future) if instance && Native.future_api? until status_holder[:done] raise_timeout!(timeout) if deadline && monotonic_time >= deadline waited = false if instance && wait_info waited = wait_with_wait_any(instance, wait_info) elsif instance instance.process_events elsif device && Native.device_poll_available? Native.wgpuDevicePoll(device.handle, 0, nil) end sleep(poll_interval) unless status_holder[:done] || waited end end |