JSPM

@webileapps/async-memoizer

0.1.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • 0
    • Score
      100M100P100Q18315F
    • License ISC

    A memoizer for asynchronous functions that memoizes the results of the resolved promise for future use.

    Package Exports

    • @webileapps/async-memoizer
    • @webileapps/async-memoizer/lib/index.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@webileapps/async-memoizer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Introduction

    This is a memoizer for asynchronous functions that return a promise.

    Usage

    import asyncMemoizer from "@webileapps/async-memoizer";
    
    async function getUserFromSomewhere(id: string) {
        return Promise.resolve({ id, name: "John" });
    }
    
    const function memoizedGetUserFromSomewhere = asyncMemoizer(getUserFromSomewhere);
    
    const [ result1, result2 ] = await Promise.all([memoizedGetUserFromSomewhere("1"), memoizedGetUserFromSomewhere("2")]);
    
    const [ result3, result4 ] = await Promise.all([memoizedGetUserFromSomewhere("1"), memoizedGetUserFromSomewhere("2")]);
    
    // In the above case, the second calls to getUserFromSomewhere will be skipped as the results are memoized