WorkletQueueFactory
interface WorkletQueueFactory extends HybridObjectThe WorkletQueueFactory allows creating WorkletQueues
from NativeThreads.
Methods
getCurrentThreadMarker()
getCurrentThreadMarker(): numberGet a C++ Thread's incrementing marker.
The first thread that calls this gets 1.
The second thread that calls this gets 2.
If the first thread calls it again, it gets 1 again.
This is useful for rendering libraries that are Thread-confined (like OpenGL) to ensure state is cached per-Thread.
A Thread Marker does not correlate to modern
queues - a DispatchQueue might use multiple
Threads from a pool, and therefore has
different Thread Markers.
wrapThreadInQueue()
wrapThreadInQueue(thread: NativeThread): WorkletQueueWraps the given NativeThread in
a WorkletQueue, which can later be
used to create a Worklet Runtime that runs on
the given NativeThread.
Typically you would use a NativeThread
from an output, such as CameraFrameOutput.thread,
but you can also create your own NativeThread
via createNativeThread(...).
Examples
Creating a Worklet Runtime for a Frame Output's Thread:
const frameOutput = ...
const thread = frameOutput.thread
const queue = WorkletQueueFactory.wrapThreadInQueue(thread)
const runtime = createWorkletRuntime({
name: thread.id,
customQueue: workletQueue,
useDefaultQueue: false,
})Creating a Worklet Runtime for a custom Thread:
const thread = NativeThreadFactory.createNativeThread('my-thread')
const queue = WorkletQueueFactory.wrapThreadInQueue(thread)
const runtime = createWorkletRuntime({
name: thread.id,
customQueue: workletQueue,
useDefaultQueue: false,
})