@lynx-js/react / runOnBackground

Function: runOnBackground()

function runOnBackground<R, Fn>(f: Fn): (...args: Parameters<Fn>) => Promise<R>

runOnBackground allows triggering js functions on the background thread asynchronously.

Type Parameters

Type Parameter
R
Fn extends (...args: any[]) => R

Parameters

ParameterTypeDescription
fFnThe js function to be called.

Returns

Function

A function. Calling which with the arguments to be passed to the js function to trigger it on the background thread. This function returns a promise that resolves to the return value of the js function.

Parameters

ParameterType
...argsParameters<Fn>

Returns

Promise<R>

Example

import { runOnBackground } from '@lynx-js/react';

async function someMainthreadFunction() {
  'main thread';
  const fn = runOnBackground(() => {
    return 'hello';
  });
  const result = await fn();
}

Defined in

@lynx-js/react/runtime/lib/worklet/call/runOnBackground.d.ts:19

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.