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
范围 🌐 Parameter | 类型 🌐 Type | 描述 🌐 Description |
|---|---|---|
func | 函数 | 字符串 🌐 Func | string | 待评估的功能。 🌐 Function to be evaluated. |
args | 参数 🌐 Params | 要传递给 🌐 Arguments to pass into |
返回:
Promise<HandleFor<Awaited<ReturnType<Func>>>>
func 的返回值的 句柄。
🌐 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.