@lynx-js/react / runOnMainThread

函数: runOnMainThread()

function runOnMainThread<R, Fn>(fn: Fn): (...args: Parameters<Fn>) => Promise<R>

runOnMainThread allows triggering main thread functions on the main thread asynchronously.

类型参数

类型参数
R
Fn extends (...args: any[]) => R

参数

范围类型描述
fnFnThe main thread functions to be called.

返回

Function

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

参数

范围类型
...argsParameters<Fn>

返回

Promise<R>

示例

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

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

定义于

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

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