From 936b8c31e7515e8938b3e4e3b1049838d5ee5811 Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Fri, 18 Aug 2017 04:04:54 -0700 Subject: [PATCH] metro-bundler: elaborate the global cache test a bit Reviewed By: davidaurelio Differential Revision: D5650882 fbshipit-source-id: b1f283f00e6e200f3b731126ed7a273fe782aeaa --- .../src/lib/GlobalTransformCache.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/metro-bundler/src/lib/GlobalTransformCache.js b/packages/metro-bundler/src/lib/GlobalTransformCache.js index 7a6549b5..40d9c49d 100644 --- a/packages/metro-bundler/src/lib/GlobalTransformCache.js +++ b/packages/metro-bundler/src/lib/GlobalTransformCache.js @@ -50,13 +50,14 @@ export type GlobalTransformCache = { fetch(props: FetchProps): Promise, /** - * Try to store a result, without waiting for the success or failure of the - * operation. Consequently, the actual storage operation could be done at a - * much later point if desired. It is recommended to actually have this - * function be a no-op in production, and only do the storage operation from - * a script running on your Continuous Integration platform. + * Try to store a result. Callsites won't necessarily wait for the success or + * failure of the Promise, so errors may be handled internally, they may + * otherwise be silently ignored. The actual storage operation could be done + * at a later point if desired. It is recommended to have this function be a + * no-op in production, and only do the storage operation from a script + * running on a Continuous Integration platform. */ - store(props: FetchProps, result: CachedResult): void, + store(props: FetchProps, result: CachedResult): Promise, }; type FetchResultURIs = (keys: Array) => Promise>; @@ -112,6 +113,7 @@ type KeyedResult = {key: string, result: CachedResult}; class KeyResultStore { _storeResults: StoreResults; _batchProcessor: BatchProcessor; + _promises: Array>; async _processResults(keyResults: Array): Promise> { const resultsByKey = new Map( @@ -121,8 +123,8 @@ class KeyResultStore { return new Array(keyResults.length); } - store(key: string, result: CachedResult) { - this._batchProcessor.queue({key, result}); + async store(key: string, result: CachedResult): Promise { + await this._batchProcessor.queue({key, result}); } constructor(storeResults: StoreResults) { @@ -135,6 +137,7 @@ class KeyResultStore { }, this._processResults.bind(this), ); + this._promises = []; } } @@ -346,9 +349,9 @@ class URIBasedGlobalTransformCache { return await this._fetchResultFromURI(uri); } - store(props: FetchProps, result: CachedResult) { + async store(props: FetchProps, result: CachedResult): Promise { if (this._store != null) { - this._store.store(this.keyOf(props), result); + await this._store.store(this.keyOf(props), result); } } }