For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt, and this page is available as Markdown at /next/zh/api/react/Functions/runOnMainThread.md.
  • 简体中文
  • 函数: runOnMainThread()

    runOnMainThread<R, Fn extends (...args: any[]) => R>(fn: Fn): (...args: Parameters<Fn>) => Promise<R>

    runOnMainThread 用于在主线程上异步触发主线程函数。

    类型参数

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

    参数

    参数类型描述
    fnFn要调用的主线程函数。

    返回

    一个函数。以要传给该主线程函数的参数调用它,即可在主线程上触发该主线程函数。该函数返回一个 Promise,其 resolve 值为该主线程函数的返回值。

    (...args: Parameters<Fn>) => Promise<R>

    示例

    import { runOnMainThread } from '@lynx-js/react';
    
    async function someFunction() {
      const fn = runOnMainThread(() => {
        'main thread';
        return 'hello';
      });
      const result = await fn();
    }
    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。