Skip to content

Commit ce02edf

Browse files
committed
Clarify destruction and download stopping
1 parent 2cb6637 commit ce02edf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,17 @@ const languageDetector = await ai.languageDetector.create({ signal: controller.s
184184
await languageDetector.detect(document.body.textContent, { signal: controller.signal });
185185
```
186186

187-
Additionally, the language detector and translator objects themselves have a `destroy()` method. Calling this method will:
187+
Destroying a translator or language detector will:
188188

189-
* Abort any ongoing downloads or loading process for the language detector or translator model.
190-
* Reject any ongoing calls to `detect()` or `translate()` with a `"AbortError"` `DOMException`.
191-
* Error any `ReadableStream`s returned by `translateStreaming()` with a `"AbortError"` `DOMException`.
189+
* Reject any ongoing calls to `detect()` or `translate()`.
190+
* Error any `ReadableStream`s returned by `translateStreaming()`.
192191
* And, most importantly, allow the user agent to unload the machine learning models from memory. (If no other APIs are using them.)
193192

194-
This method is mainly used as a mechanism to free up the memory used by the model without waiting for garbage collection, since machine learning models can be quite large.
193+
Allowing such destruction provides a way to free up the memory used by the model without waiting for garbage collection, since machine learning models can be quite large.
194+
195+
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.)
196+
197+
In all cases, the exception used for rejecting promises or erroring `ReadableStream`s will be an `"AbortError"` `DOMException`, or the given abort reason.
195198

196199
## Detailed design
197200

0 commit comments

Comments
 (0)