Skip to content

Commit 9c3a741

Browse files
committed
Add shutdown API reference page [doc only]
1 parent af41bac commit 9c3a741

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

docs/user/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- [Toggling upload status](reference/general/toggling-upload-status.md)
3939
- [Annotating experiments](reference/general/experiments-api.md)
4040
- [Registering custom pings](reference/general/register-custom-pings.md)
41+
- [Shut down](reference/general/shutdown.md)
4142
- [Debugging](reference/debug/index.md)
4243
- [Log pings](reference/debug/logPings.md)
4344
- [Debug View Tag](reference/debug/debugViewTag.md)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Shut down
2+
3+
Provides a way for users to gracefully shut down Glean,
4+
by blocking until it is finished performing pending tasks,
5+
such as recording metrics and uploading pings.
6+
7+
{{#include ../../../shared/blockquote-info.html}}
8+
9+
## How the Glean SDKs execute tasks
10+
11+
> Most calls to Glean APIs are dispatched[^1]. This strategy is adopted, because most tasks
12+
> performed by the Glean SDKs involve file system read or write operations, HTTP requests or
13+
> other time consuming actions.
14+
>
15+
> Each Glean SDK has an internal structure called "Dispatcher" which makes sure API calls
16+
> get executed in the order they were called, while not requiring the caller to block on the
17+
> completion of each of these tasks.
18+
>
19+
> [^1]: Here this term indicates the tasks are run asynchronously in JavaScript or in a different
20+
> thread for all other SDKs.
21+
22+
## API
23+
24+
### `shutdown`
25+
26+
{{#include ../../../shared/tab_header.md}}
27+
<div data-lang="Kotlin" class="tab"></div>
28+
<div data-lang="Java" class="tab"></div>
29+
<div data-lang="Swift" class="tab"></div>
30+
<div data-lang="Python" class="tab"></div>
31+
<div data-lang="Rust" class="tab"></div>
32+
<div data-lang="JavaScript" class="tab">
33+
34+
```js
35+
import Glean from "@mozilla/glean/webext";
36+
37+
async function onUninstall() {
38+
// Flips Glean upload status to `false`,
39+
// which triggers sending of a `deletion-request` ping.
40+
Glean.setUploadEnabled(false);
41+
42+
// Block on `shutdown` to guarantee the `deletion-request` ping is
43+
// sent before the extension is uninstalled.
44+
await Glean.shutdown();
45+
46+
// Uninstall browser extension without asking for user approval before doing so.
47+
await browser.management.uninstallSelf({ showConfirmDialog: false });
48+
}
49+
```
50+
51+
The `shutdown` API is available for all JavaScript targets, even though the above example
52+
is explicitly using the `webext` target.
53+
</div>
54+
<div data-lang="Firefox Desktop" class="tab"></div>
55+
{{#include ../../../shared/tab_footer.md}}
56+
57+
## Reference
58+
59+
* [JavaScript API docs](TODO)

0 commit comments

Comments
 (0)