mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Call this.unblock() in __dynamicImport method.
This prevents __dynamicImport from blocking other method calls made by the application, but introduces the possibility that __dynamicImport method results could be delivered out of order, which is now handled in the fetchMissing function.
This commit is contained in:
@@ -58,13 +58,34 @@ Module.prototype.dynamicImport = function (id) {
|
||||
});
|
||||
};
|
||||
|
||||
// Results from fetchMissing must be delivered in the same order as calls
|
||||
// to fetchMissing, because previous results may include modules needed by
|
||||
// more recent calls. In practice, results are usually delivered in order,
|
||||
// but might be delivered out of order because the __dynamicImport method
|
||||
// calls this.unblock(). To achieve this ordering of results while still
|
||||
// allowing parallel __dynamicImport method calls, we keep track of the
|
||||
// most recent Promise returned by fetchMissing, and delay resolving the
|
||||
// next Promise until the previous Promise has been resolved or rejected.
|
||||
var lastFetchMissingPromise = delayPromise;
|
||||
|
||||
function fetchMissing(missingTree) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
// Save the Promise that was most recent when fetchMissing was called.
|
||||
var previousPromise = lastFetchMissingPromise;
|
||||
|
||||
// Update lastFetchMissingPromise immediately, without waiting for
|
||||
// the results to be delivered.
|
||||
return lastFetchMissingPromise = new Promise(function (resolve, reject) {
|
||||
Meteor.call(
|
||||
"__dynamicImport",
|
||||
missingTree,
|
||||
function (error, resultsTree) {
|
||||
error ? reject(error) : resolve(resultsTree);
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve = resolve.bind(null, resultsTree)
|
||||
// Continue even if previousPromise was rejected.
|
||||
previousPromise.then(resolve, resolve);
|
||||
}
|
||||
}
|
||||
);
|
||||
}).then(installResults);
|
||||
|
||||
@@ -22,6 +22,7 @@ Object.keys(dynamicImportInfo).forEach(platform => {
|
||||
Meteor.methods({
|
||||
__dynamicImport(tree) {
|
||||
check(tree, Object);
|
||||
this.unblock();
|
||||
|
||||
const platform = this.connection ? "web.browser" : "server";
|
||||
const pathParts = [];
|
||||
|
||||
Reference in New Issue
Block a user