@@ -274,6 +274,108 @@ if (isMainThread) {
274
274
}
275
275
```
276
276
277
+ ## ` worker.locks `
278
+ <!-- YAML
279
+ added: REPLACEME
280
+ -->
281
+
282
+ > Stability: 1 - Experimental
283
+
284
+ * {LockManager}
285
+
286
+ An instance of a [ ` LockManager ` ] [ ] .
287
+
288
+ ### Class: ` Lock `
289
+ <!-- YAML
290
+ added: REPLACEME
291
+ -->
292
+
293
+ The Lock interface provides the name and mode of a previously requested lock,
294
+ which is received in the callback to [ ` locks.request() ` ] [ ] .
295
+
296
+ #### ` lock.name `
297
+ <!-- YAML
298
+ added: REPLACEME
299
+ -->
300
+
301
+ * {string}
302
+
303
+ The name of this lock.
304
+
305
+ #### ` lock.mode `
306
+ <!-- YAML
307
+ added: REPLACEME
308
+ -->
309
+
310
+ * {string}
311
+
312
+ The mode of this lock. Either ` shared ` or ` exclusive ` .
313
+
314
+ ### Class: ` LockManager `
315
+ <!-- YAML
316
+ added: REPLACEME
317
+ -->
318
+
319
+ The ` LockManager ` interface provides methods for requesting a new [ ` Lock ` ] [ ]
320
+ object and querying for an existing ` Lock ` object. To get an instance of
321
+ ` LockManager ` , call ` worker_threads.locks ` .
322
+
323
+ With the exception of ` AbortController ` support, this implementation matches
324
+ the [ browser ` LockManager ` ] [ ] API.
325
+
326
+ #### ` locks.request(name[, options], callback) `
327
+ <!-- YAML
328
+ added: REPLACEME
329
+ -->
330
+
331
+ * ` name ` {string}
332
+ * ` options ` {Object}
333
+ * ` mode ` {string} Either ` 'exclusive' ` or ` 'shared' ` . ** Default:**
334
+ ` 'exclusive' ` .
335
+ * ` ifAvailable ` {boolean} If ` true ` , the lock request will only be
336
+ granted if it is not already held. If it cannot be granted, the
337
+ callback will be invoked with ` null ` instead of a ` Lock ` instance.
338
+ ** Default:** ` false ` .
339
+ * ` steal ` {boolean} If ` true ` , then any held locks with the same name will be
340
+ released, and the request will be granted, preempting any queued requests
341
+ for it. ** Default:** ` false ` .
342
+ * ` callback ` {Function} The function to be invoked while the lock is acquired.
343
+ The lock will be released when the function ends, or if the function returns
344
+ a promise, when that promise settles.
345
+ * Returns: {Promise}
346
+
347
+ Requests a [ ` Lock ` ] [ ] object with parameters specifying its name and
348
+ characteristics.
349
+
350
+ ``` js
351
+ worker_threads .locks .request (' my_resource' , async (lock ) => {
352
+ // The lock was granted.
353
+ }).then (() => {
354
+ // The lock is released here.
355
+ });
356
+ ```
357
+
358
+ #### ` locks.query() `
359
+ <!-- YAML
360
+ added: REPLACEME
361
+ -->
362
+
363
+ * Returns: {Promise}
364
+
365
+ Returns a Promise that resolves with a [ ` LockManagerSnapshot ` ] [ ] which contains
366
+ information about held and pending locks.
367
+
368
+ ``` js
369
+ worker_threads .locks .query ().then ((state ) => {
370
+ state .held .forEach ((lock ) => {
371
+ console .log (` held lock: name ${ lock .name } , mode ${ lock .mode } ` );
372
+ });
373
+ state .pending .forEach ((request ) => {
374
+ console .log (` requested lock: name ${ request .name } , mode ${ request .mode } ` );
375
+ });
376
+ });
377
+ ```
378
+
277
379
## Class: ` BroadcastChannel extends EventTarget `
278
380
<!-- YAML
279
381
added: v15.4.0
@@ -1086,6 +1188,9 @@ active handle in the event system. If the worker is already `unref()`ed calling
1086
1188
[ `EventTarget` ] : https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
1087
1189
[ `FileHandle` ] : fs.md#fs_class_filehandle
1088
1190
[ `KeyObject` ] : crypto.md#crypto_class_keyobject
1191
+ [ `Lock` ] : #worker_threads_class_lock
1192
+ [ `LockManager` ] : #worker_threads_class_lockmanager
1193
+ [ `LockManagerSnapshot` ] : https://developer.mozilla.org/en-US/docs/Web/API/LockManagerSnapshot
1089
1194
[ `MessagePort` ] : #worker_threads_class_messageport
1090
1195
[ `SharedArrayBuffer` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
1091
1196
[ `Uint8Array` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
@@ -1095,6 +1200,7 @@ active handle in the event system. If the worker is already `unref()`ed calling
1095
1200
[ `data:` URL ] : https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
1096
1201
[ `fs.close()` ] : fs.md#fs_fs_close_fd_callback
1097
1202
[ `fs.open()` ] : fs.md#fs_fs_open_path_flags_mode_callback
1203
+ [ `locks.request()` ] : #worker_threads_locks_request_name_options_callback
1098
1204
[ `markAsUntransferable()` ] : #worker_threads_worker_markasuntransferable_object
1099
1205
[ `perf_hooks.performance` ] : perf_hooks.md#perf_hooks_perf_hooks_performance
1100
1206
[ `perf_hooks` `eventLoopUtilization()` ] : perf_hooks.md#perf_hooks_performance_eventlooputilization_utilization1_utilization2
@@ -1126,6 +1232,7 @@ active handle in the event system. If the worker is already `unref()`ed calling
1126
1232
[ `worker.terminate()` ] : #worker_threads_worker_terminate
1127
1233
[ `worker.threadId` ] : #worker_threads_worker_threadid_1
1128
1234
[ async-resource-worker-pool ] : async_hooks.md#async-resource-worker-pool
1235
+ [ browser `LockManager` ] : https://developer.mozilla.org/en-US/docs/Web/API/LockManager
1129
1236
[ browser `MessagePort` ] : https://developer.mozilla.org/en-US/docs/Web/API/MessagePort
1130
1237
[ child processes ] : child_process.md
1131
1238
[ contextified ] : vm.md#vm_what_does_it_mean_to_contextify_an_object
0 commit comments