Skip to content

Commit b0751b9

Browse files
committed
Clarify session destruction and download stopping
Closes #30.
1 parent 6371b94 commit b0751b9

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,23 @@ or by calling `destroy()` on the session:
179179
stopButton.onclick = () => session.destroy();
180180
```
181181

182-
Destroying a session will:
182+
Destroying a session will have the following effects:
183183

184-
* Abort any ongoing downloads or loading process for the language model.
184+
* If done before the promise returned by `create()` is settled:
185185

186-
* Reject any ongoing calls to `prompt()` with an `"AbortError"` `DOMException` (or the given abort reason).
186+
* Stop signaling any ongoing download progress for the language model. (The browser may also abort the download, or may continue it. Either way, no further `downloadprogress` events will fire.)
187187

188-
* Error any `ReadableStream`s returned by `promptStreaming()` with an `"AbortError"` `DOMException` (or the given abort reason).
188+
* Reject the `create()` promise.
189189

190-
* And, most importantly, allow the user agent to unload the language model from memory. (If no other APIs or sessions are using it.)
190+
* Otherwise:
191+
192+
* Reject any ongoing calls to `prompt()`.
193+
194+
* Error any `ReadableStream`s returned by `promptStreaming()`.
195+
196+
* Most importantly, destroying the session allows the user agent to unload the language model from memory, if no other APIs or sessions are using it.
197+
198+
In all cases the exception used for rejecting promises or erroring `ReadableStream`s will be an `"AbortError"` `DOMException`, or the given abort reason.
191199

192200
The ability to manually destroy a session allows applications to free up memory without waiting for garbage collection, which can be useful since language models can be quite large.
193201

0 commit comments

Comments
 (0)