@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

除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。