Created
April 20, 2018 18:48
-
-
Save freaktechnik/80dda043b233190ed5cfd0dfc0d5bd5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * A Promise that centralizes initialization of ExtensionStorageSync. | |
| * | |
| * This centralizes the use of the Sqlite database, to which there is | |
| * only one connection which is shared by all threads. | |
| * | |
| * Fields in the object returned by this Promise: | |
| * | |
| * - connection: a Sqlite connection. Meant for internal use only. | |
| * - kinto: a KintoBase object, suitable for using in Firefox. All | |
| * collections in this database will use the same Sqlite connection. | |
| * @returns {Promise<Object>} | |
| */ | |
| async function storageSyncInit() { | |
| // Memoize the result to share the connection. | |
| if (storageSyncInit.promise === undefined) { | |
| const path = "storage-sync.sqlite"; | |
| /** | |
| * @static | |
| * @type {Promise<Object>} | |
| */ | |
| storageSyncInit.promise = FirefoxAdapter.openConnection({path}) | |
| .then(connection => { | |
| return { | |
| connection, | |
| kinto: new Kinto({ | |
| adapter: FirefoxAdapter, | |
| adapterOptions: {sqliteHandle: connection}, | |
| timeout: KINTO_REQUEST_TIMEOUT, | |
| retry: 0, | |
| }), | |
| }; | |
| }).catch(e => { | |
| // Ensure one failure doesn't break us forever. | |
| Cu.reportError(e); | |
| storageSyncInit.promise = undefined; | |
| throw e; | |
| }); | |
| } | |
| return storageSyncInit.promise; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment