@@ -39,12 +39,23 @@ When data is submitted, the Glean SDK is responsible for assembling the correct
3939storage. Each metric can have different [ lifetimes] ( https://mozilla.github.io/glean/book/user/metrics/adding-new-metrics.html#a-lifetime-example )
4040and the SDK will manage its storage so that data does not remain in storage after it's lifetime is expired.
4141
42- The Glean SDK tries to do all of this is the least disruptive way possible to users. All of the
43- SDKs tasks are queued and executed asynchronously. The APIs exposed by the Glean SDK will only do
42+ The Glean SDK tries to do all of this is the least disruptive way possible to users. There are two separate
43+ implementations for the SDK based on the platform: async (QT, node, web extensions) and sync (browser). The implementation
44+ is set inside of Glean itself and is not configurable by the user.
45+
46+ ### async (Web Extensions, QT, Node)
47+
48+ All of the SDKs tasks are queued and executed asynchronously. The APIs exposed by the Glean SDK will only do
4449the en-queuing of tasks, a quick synchronous operation. Internally, the Glean SDK will handle the
4550queued tasks asynchronously, catching any errors thrown along the way so that Glean never
4651crashes a users application.
4752
53+ ### sync (Browser)
54+
55+ All of the SDKs tasks are executed synchronously, immediately as they are called. The APIs exposed by Glean
56+ are the same as the async implementation, but without queueing of any tasks. Errors will be caught without
57+ ever crashing the application.
58+
4859## Code Map
4960
5061The Glean JavaScript SDK source code lives under the ` glean/src ` folder.
@@ -116,6 +127,13 @@ the `platform/` module contains implementations of identical interfaces in diffe
116127This allows the pattern of only importing the necessary implementation of these modules on each platform.
117128It also makes testing easier, because the exact same suite of tests can be run for each of the platform-specific implementations,
118129 thus guaranteeing that each module works exactly the same on all platforms.
130+
131+ The storage module varies for each platform. The storage mechanism used by each platform is as follows:
132+ - ` web ` - [ ` localStorage ` ] ( https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage )
133+ - ` webext ` - [ ` storage ` ] ( https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage )
134+ - ` QT ` - [ ` QtQuick.LocalStorage ` ] ( https://doc.qt.io/qt-6/qtquick-localstorage-qmlmodule.html )
135+ - ` Node ` - None, everything is stored in memory
136+
119137### ` plugins/ `
120138
121139The ` plugins/ ` folder contains the Glean.js' plugins code.
@@ -127,3 +145,15 @@ exposed through the `@mozilla/glean/plugins/*` entry point.
127145
128146This file is what gets executed when a user that has installed Glean through npm invokes the ` glean `
129147command. It serves as a wrapper to call ` glean_parser ` commands more easily from JavaScript projects.
148+
149+ ### ` async ` /` sync ` files
150+
151+ There are certain places where we need different implementations for internal services based on the
152+ platform. In these instances, the service will have its own folder with the following folder structure:
153+
154+ ```
155+ ├── service/
156+ ├──── async.ts
157+ ├──── shared.ts # Shared base class defining all available methods AND any reusable helper functions
158+ └──── sync.ts
159+ ```
0 commit comments