diff --git a/src/extension-support/extension-manager.js b/src/extension-support/extension-manager.js index 66235b24a..edbf7ceac 100644 --- a/src/extension-support/extension-manager.js +++ b/src/extension-support/extension-manager.js @@ -144,18 +144,21 @@ class ExtensionManager { } /** - * regenerate blockinfo for any loaded extensions - */ + * Regenerate blockinfo for any loaded extensions + * @returns {Promise} resolved once all the extensions have been reinitialized + */ refreshBlocks () { - this._loadedExtensions.forEach(serviceName => { + const allPromises = Array.from(this._loadedExtensions.values()).map(serviceName => dispatch.call(serviceName, 'getInfo') .then(info => { + info = this._prepareExtensionInfo(serviceName, info); dispatch.call('runtime', '_refreshExtensionPrimitives', info); }) .catch(e => { log.error(`Failed to refresh buildtin extension primitives: ${JSON.stringify(e)}`); - }); - }); + }) + ); + return Promise.all(allPromises); } allocateWorker () { diff --git a/src/virtual-machine.js b/src/virtual-machine.js index e95258fb4..822f06ced 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -907,12 +907,15 @@ class VirtualMachine extends EventEmitter { * set the current locale and builtin messages for the VM * @param {[type]} locale current locale * @param {[type]} messages builtin messages map for current locale + * @returns {Promise} Promise that resolves when all the blocks have been + * updated for a new locale (or empty if locale hasn't changed.) */ setLocale (locale, messages) { - if (locale !== formatMessage.setup().locale) { - formatMessage.setup({locale: locale, translations: {[locale]: messages}}); - this.extensionManager.refreshBlocks(); + if (locale === formatMessage.setup().locale) { + return Promise.resolve(); } + formatMessage.setup({locale: locale, translations: {[locale]: messages}}); + return this.extensionManager.refreshBlocks(); } /**