Skip to main content
Version: 23.2.0

WebWorker.evaluateHandle() 方法

¥WebWorker.evaluateHandle() method

评估 worker 中的给定函数。

¥Evaluates a given function in the worker.

签名

¥Signature

class WebWorker {
evaluateHandle<
Params extends unknown[],
Func extends EvaluateFunc<Params> = EvaluateFunc<Params>,
>(
func: Func | string,
...args: Params
): Promise<HandleFor<Awaited<ReturnType<Func>>>>;
}

参数

¥Parameters

范围

类型

描述

func

功能 | 字符串

待评估的功能。

args

参数

要传递到 func 的参数。

Returns:

Promise<HandleFor<Awaited<ReturnType<Func>>>>

一个 handlefunc 的返回值。

¥A handle to the return value of func.

备注

¥Remarks

如果给定函数返回一个 Promise,evaluate 将等待 Promise 解析。

¥If the given function returns a promise, evaluate will wait for the promise to resolve.

一般来说,如果 evaluate 无法正确序列化返回值或者你需要一个可变的 handle 作为返回对象,则应该使用 evaluateHandle

¥In general, you should use evaluateHandle if evaluate cannot serialize the return value properly or you need a mutable handle to the return object.