From f83fc2986ea9222e68d2e24013876a208a655f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 7 Oct 2019 12:37:03 +0200 Subject: [PATCH] Cleanup --- packages/babel-core/src/config/caching.js | 52 +++++++++---------- .../babel-core/src/gensync-utils/async.js | 2 +- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/packages/babel-core/src/config/caching.js b/packages/babel-core/src/config/caching.js index 1ad7050f5db4..fcad6e8fccbe 100644 --- a/packages/babel-core/src/config/caching.js +++ b/packages/babel-core/src/config/caching.js @@ -1,7 +1,5 @@ // @flow -/*:: declare var invariant; */ - import gensync, { type Handler } from "gensync"; import { maybeAsync, @@ -73,6 +71,31 @@ export function makeStrongCacheSync( ); } +/* NOTE: Part of the logic explained in this comment is explained in the + * getCachedValueOrWait and setupAsyncLocks functions. + * + * > There are only two hard things in Computer Science: cache invalidation and naming things. + * > -- Phil Karlton + * + * I don't know if Phil was also thinking about handling a cache whose invalidation function is + * defined asynchronously is considered, but it is REALLY hard to do correctly. + * + * The implemented logic (only when gensync is run asynchronously) is the following: + * 1. If there is a valid cache associated to the current "arg" parameter, + * a. RETURN the cached value + * 3. If there is a FinishLock associated to the current "arg" parameter representing a valid cache, + * a. Wait for that lock to be released + * b. RETURN the value associated with that lock + * 5. Start executing the function to be cached + * a. If it pauses on a promise, then + * i. Let FinishLock be a new lock + * ii. Store FinishLock as associated to the current "arg" parameter + * iii. Wait for the function to finish executing + * iv. Release FinishLock + * v. Send the function result to anyone waiting on FinishLock + * 6. Store the result in the cache + * 7. RETURN the result + */ function makeCachedFunction( CallCache: Class, handler: (ArgT, CacheConfigurator) => Handler | ResultT, @@ -150,30 +173,6 @@ function* getCachedValue< return { valid: false, value: null }; } -/* NOTE: This comment refers to both the getCachedValueOrWait and setupAsyncLocks functions. - * - * > There are only two hard things in Computer Science: cache invalidation and naming things. - * > -- Phil Karlton - * - * I don't know if Phil was also thinking about handling a cache whose invalidation function is - * defined asynchronously is considered, but it is REALLY hard to do correctly. - * - * The implemented logic (only when gensync is run asynchronously) is the following: - * 1. If there is a valid cache associated to the current "arg" parameter, - * a. RETURN the cached value - * 3. If there is a FinishLock associated to the current "arg" parameter representing a valid cache, - * a. Wait for that lock to be released - * b. RETURN the value associated with that lock - * 5. Start executing the function to be cached - * a. If it pauses on a promise, then - * i. Let FinishLock be a new lock - * ii. Store FinishLock as associated to the current "arg" parameter - * iii. Wait for the function to finish executing - * iv. Release FinishLock - * v. Send the function result to anyone waiting on FinishLock - * 6. Store the result in the cache - * 7. RETURN the result - */ function* getCachedValueOrWait( asyncContext: boolean, callCache: CacheMap, @@ -253,7 +252,6 @@ class CacheConfigurator { _invalidate: boolean = false; _configured: boolean = false; - _configuredHandler: ?Function = null; _pairs: Array<[mixed, (SideChannel) => Handler]> = []; diff --git a/packages/babel-core/src/gensync-utils/async.js b/packages/babel-core/src/gensync-utils/async.js index 5fd44e39357c..84edcc394135 100644 --- a/packages/babel-core/src/gensync-utils/async.js +++ b/packages/babel-core/src/gensync-utils/async.js @@ -14,7 +14,7 @@ const runGenerator = gensync(function*(item) { // asynchronous, otherwise it returns false. export const isAsync = gensync<[], boolean>({ sync: () => false, - async: async () => true, + errback: cb => cb(null, true), }); // This function wraps any functions (which could be either synchronous or