Skip to content

Commit aa9049d

Browse files
authored
Merge pull request WICG#228 from WICG/yao-explainer-ignore-batch-inner-locks
[Explainer] Ignore batch inner locks and support atomic batch updates
2 parents 8b0b7dd + 08dc7b0 commit aa9049d

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ The shared storage worklet invocation methods (`addModule`, `createWorklet`, and
152152
* Options include:
153153
* `withLock`: acquire a lock on the designated resource before executing. See [Locking for modifier methods](#locking-for-modifier-methods) for details.
154154
* `window.sharedStorage.batchUpdate(methods, options)`
155-
* Execute `methods` in order.
156-
* `methods` is an array of method objects defining the operations to perform. Each object must be one of the following types: `SharedStorageSetMethod`, `SharedStorageAppendMethod`, `SharedStorageDeleteMethod`, or `SharedStorageClearMethod`. Each method object's constructor accepts the same parameters as the corresponding individual method (e.g., `set`, `append`, `delete`, `clear`).
155+
* Execute `methods` in order. All updates within a `batchUpdate()` call are executed as a single unit of work. If any method fails, none of them will commit.
156+
* `methods` is an array of method objects defining the operations to perform. Each object must be one of the following types: `SharedStorageSetMethod`, `SharedStorageAppendMethod`, `SharedStorageDeleteMethod`, or `SharedStorageClearMethod`. Each method object's constructor accepts the same parameters as the corresponding individual method (e.g., `set`, `append`, `delete`, `clear`). Note that the `withLock` option within these methods will be ignored (for transactional behavior), but the lock for the `batchUpdate()` method itself (if specified) will be acquired.
157157
* Options include:
158158
* `withLock`: acquire a lock on the designated resource before executing. See [Locking for modifier methods](#locking-for-modifier-methods) for details.
159-
* This method, with the `withLock` option, allows multiple modifier methods to be executed atomically, enabling use cases where a website needs to maintain consistency while updating data organized across multiple keys.
159+
* This method, with the `withLock` option, allows multiple modifier methods to be executed atomically and mutually exclusively with other concurrent operations acquiring the same lock, enabling use cases where a website needs to maintain consistency while updating data organized across multiple keys.
160160
* `window.sharedStorage.worklet.addModule(url, options)`
161161
* Loads and adds the module to the worklet (i.e. for registering operations). The handling should follow the [worklet standard](https://html.spec.whatwg.org/multipage/worklets.html#dom-worklet-addmodule), unless clarified otherwise below.
162162
* This method can only be invoked once per worklet. This is because after the initial script loading, shared storage data (for the invoking origin) will be made accessible inside the worklet environment, which can be leaked via subsequent `addModule()` (e.g. via timing).
@@ -264,7 +264,6 @@ The shared storage worklet invocation methods (`addModule`, `createWorklet`, and
264264
* The individual modifier methods correspond to [Items](https://www.rfc-editor.org/rfc/rfc8941.html#name-items) as follows:
265265
* `set(<key>, <value>, {ignoreIfPresent: true})` &larr;&rarr; `set;key=<key>;value=<value>;ignore_if_present`
266266
* `set(<key>, <value>, {ignoreIfPresent: false})` &larr;&rarr; `set;key=<key>;value=<value>;ignore_if_present=?0`
267-
* `set(<key>, <value>, {withLock: <resource>})` &larr;&rarr; `set;key=<key>;value=<value>;with_lock=<resource>`
268267
* `set(<key>, <value>)` &larr;&rarr; `set;key=<key>;value=<value>`
269268
* `append(<key>, <value>)` &larr;&rarr; `append;key=<key>;value=<value>`
270269
* `delete(<key>)` &larr;&rarr; `delete;key=<key>`
@@ -471,15 +470,15 @@ On the client side, to initiate the request:
471470
472471
On the server side, here is an example response header:
473472
```text
474-
Shared-Storage-Write: clear, set;key="hello";value="world";ignore_if_present;with_lock="lock2", append;key="good";value="bye", delete;key="hello", set;key="all";value="done", options;with_lock="lock1"
473+
Shared-Storage-Write: clear, set;key="hello";value="world";ignore_if_present, append;key="good";value="bye", delete;key="hello", set;key="all";value="done", options;with_lock="lock1"
475474
```
476475

477476
Sending the above response header would be equivalent to making the following call on the client side, from either the document or a worklet:
478477
```js
479478

480479
sharedStorage.batchUpdate([
481480
new SharedStorageClearMethod(),
482-
new SharedStorageSetMethod("hello", "world", {ignoreIfPresent: true, withLock: "lock2"}),
481+
new SharedStorageSetMethod("hello", "world", {ignoreIfPresent: true}),
483482
new SharedStorageAppendMethod("good", "bye"),
484483
new SharedStorageDeleteMethod("hello"),
485484
new SharedStorageSetMethod("all", "done")

0 commit comments

Comments
 (0)