aboutsummaryrefslogtreecommitdiff
path: root/javascript
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2018-09-25 17:48:17 +0100
committerDavid Baker <dave@matrix.org>2018-09-25 17:48:17 +0100
commitdfbe8a4796747b0a732f0eb322a37de99a2d2eb9 (patch)
tree48e2a360a75fad63c3ce1391d904f8079d8dfa81 /javascript
parent263b94428a24caaa5b899ed7f73b896620e6cdf4 (diff)
Return same promise if init() called many times
So we only init the library once.
Diffstat (limited to 'javascript')
-rw-r--r--javascript/olm_suffix.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/javascript/olm_suffix.js b/javascript/olm_suffix.js
index 023c0a5..ec0e39b 100644
--- a/javascript/olm_suffix.js
+++ b/javascript/olm_suffix.js
@@ -1,5 +1,8 @@
+var olmInitPromise;
+
olm_exports['init'] = function() {
- return new Promise(function(resolve, reject) {
+ if (olmInitPromise) return olmInitPromise;
+ olmInitPromise = new Promise(function(resolve, reject) {
onInitSuccess = function() {
resolve();
};
@@ -8,6 +11,7 @@ olm_exports['init'] = function() {
};
Module();
});
+ return olmInitPromise;
};
if (typeof(window) !== 'undefined') {