Return same promise if init() called many times
So we only init the library once.
This commit is contained in:
parent
263b94428a
commit
dfbe8a4796
1 changed files with 5 additions and 1 deletions
|
@ -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') {
|
||||
|
|
Loading…
Reference in a new issue