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/Function.runOnBackground.md.
  • 简体中文
  • @lynx-js/react / runOnBackground

    函数: runOnBackground()

    function runOnBackground<R, Fn>(f: Fn): (...args: Parameters<Fn>) => Promise<R>

    runOnBackground allows triggering js functions on the background thread asynchronously.

    类型参数

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

    参数

    范围类型描述
    fFnThe js function to be called.

    返回

    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.

    参数

    范围类型
    ...argsParameters<Fn>

    返回

    Promise<R>

    示例

    import { runOnBackground } from '@lynx-js/react';
    
    async function someMainthreadFunction() {
      'main thread';
      const fn = runOnBackground(() => {
        return 'hello';
      });
      const result = await fn();
    }

    定义于

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

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