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.
  • 简体中文
  • Function: runOnBackground()

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

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

    Type Parameters

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

    Parameters

    ParameterTypeDescription
    fFn要调用的 JS 函数。

    Returns

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

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

    Example

    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 许可协议进行许可。