From dfbe8a4796747b0a732f0eb322a37de99a2d2eb9 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 25 Sep 2018 17:48:17 +0100 Subject: Return same promise if init() called many times So we only init the library once. --- javascript/olm_suffix.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'javascript') 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') { -- cgit v1.2.3