Return same promise if init() called many times

So we only init the library once.
This commit is contained in:
David Baker 2018-09-25 17:48:17 +01:00
parent 263b94428a
commit dfbe8a4796

View file

@ -1,5 +1,8 @@
var olmInitPromise;
olm_exports['init'] = function() { olm_exports['init'] = function() {
return new Promise(function(resolve, reject) { if (olmInitPromise) return olmInitPromise;
olmInitPromise = new Promise(function(resolve, reject) {
onInitSuccess = function() { onInitSuccess = function() {
resolve(); resolve();
}; };
@ -8,6 +11,7 @@ olm_exports['init'] = function() {
}; };
Module(); Module();
}); });
return olmInitPromise;
}; };
if (typeof(window) !== 'undefined') { if (typeof(window) !== 'undefined') {