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/runOnBackground.md.
  • 简体中文
  • 函数: runOnBackground()

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

    runOnBackground 用于在后台线程上异步触发 JS 函数。

    类型参数

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

    参数

    参数类型描述
    fFn要调用的 JS 函数。

    返回

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

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

    示例

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