UNPKG

@aws-amplify/core

Version:
29 lines (27 loc) 1.07 kB
'use strict'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.withMemoization = void 0; /** * Cache the payload of a response body. It allows multiple calls to the body, * for example, when reading the body in both retry decider and error deserializer. * Caching body is allowed here because we call the body accessor(blob(), json(), * etc.) when body is small or streaming implementation is not available(RN). * * @internal */ const withMemoization = (payloadAccessor) => { let cached; return () => { if (!cached) { // Explicitly not awaiting. Intermediate await would add overhead and // introduce a possible race in the event that this wrapper is called // again before the first `payloadAccessor` call resolves. cached = payloadAccessor(); } return cached; }; }; exports.withMemoization = withMemoization; //# sourceMappingURL=memoization.js.map