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

Class Method Details

.callback_mode(instance:) ⇒ Integer

Selects the native callback delivery mode for an operation.

Parameters:

  • instance (Instance, nil)

    instance capable of processing events

Returns:



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_intervalFloat

Returns the delay between callback progress polls.

Returns:

  • (Float)

    seconds



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.

Parameters:

  • seconds (Numeric)

    positive delay in seconds

  • (Numeric)

Returns:

  • (Float)

Raises:

  • (ArgumentError)

    if the delay is not positive



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.

Parameters:

  • status_holder (Hash)

    state whose :done flag is set by the callback

  • timeout (Numeric, nil) (defaults to: nil)

    maximum wait time in seconds

Raises:



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