Skip to content

Commit 3938f0f

Browse files
committed
Clarify destruction and download stopping
1 parent 882bc9d commit 3938f0f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,19 @@ const rewriter = await ai.rewriter.create({ signal: controller.signal });
217217
await rewriter.rewrite(document.body.textContent, { signal: controller.signal });
218218
```
219219
220-
Additionally, the summarizer/writer/rewriter objects themselves have a `destroy()` method. Calling this method will:
220+
Additionally, the summarizer/writer/rewriter objects themselves have a `destroy()` method, which is a convenience method with equivalent behavior for cases where the summarizer/writer/rewriter object has already been created.
221221
222-
* Abort any ongoing downloads or loading process for the model.
223-
* Reject any ongoing one-shot operations (`summarize()`, `write()`, or `rewrite()`) with a `"AbortError"` `DOMException`.
224-
* Error any `ReadableStream`s returned by the streaming operations with a `"AbortError"` `DOMException`.
222+
Destroying a summarizer/writer/rewriter will:
223+
224+
* Reject any ongoing one-shot operations (`summarize()`, `write()`, or `rewrite()`).
225+
* Error any `ReadableStream`s returned by the streaming operations.
225226
* And, most importantly, allow the user agent to unload the machine learning models from memory. (If no other APIs are using them.)
226227
227-
This method is mainly used as a mechanism to free up the memory used by the language model without waiting for garbage collection, since models can be quite large.
228+
Allowing such destruction provides a way to free up the memory used by the language model without waiting for garbage collection, since models can be quite large.
229+
230+
Aborting the creation process will reject the promise returned by `create()`, and will also stop signaling any ongoing download progress. (The browser may then abort the downloads, or may continue them. Either way, no further `downloadprogress` events will be fired.)
231+
232+
In all cases, the exception used for rejecting promises or erroring `ReadableStream`s will be an `"AbortError"` `DOMException`, or the given abort reason.
228233
229234
## Detailed design
230235

0 commit comments

Comments
 (0)