close()
方法在
SharedWorkerGlobalScope
interface discards any tasks queued in the
SharedWorkerGlobalScope
's event loop, effectively closing this particular scope.
self.close();
If you want to close your worker instance from inside the worker itself, you can call the following:
close();
close()
and
self.close()
are effectively equivalent — both represent
close()
being called from inside the worker's inner scope.
注意
: There is also a way to stop the worker from the main thread: the
Worker.terminate
方法。
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'close()' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
close
|
Chrome No | Edge No | Firefox 54 | IE No | Opera No | Safari ? | WebView Android No | Chrome Android No | Firefox Android 54 | Opera Android No | Safari iOS ? | Samsung Internet Android No |
完整支持
不支持
兼容性未知
General note:
In newer browser versions,
close()
is available on
SharedWorkerGlobalScope
and
DedicatedWorkerGlobalScope
. In older browser versions, it is available on
WorkerGlobalScope
. This change was made to stop
close()
being available on service workers, as it isn't supposed to be used there and always throws an exception when called (see
bug 1336043
).
SharedWorkerGlobalScope
close()