@jcoreio/once-async
async version of lodash.once that avoids retained promise memory leaks

The Problem
The following onceified function leaks memory:
import once from 'lodash/once'
export const getOnce = once(async () => ...)
The first call creates a Promise
that is retained forever; and then
/catch
/finally
handlers registered on this
Promise
will thus also be retained forever, as well as any objects in the closure of those handlers, causing the
memory leak.
The Solution
All we need to do is discard the Promise
once it's fulfilled, keeping only the resolved value or rejection reason
for future function calls.
API
Example:
import { onceAsync } from '@jcoreio/once-async'
const fetchOnce = onceAsync(async () =>
fetch('https://com.com').then((res) => res.json())
)
The created function calls your function once with the arguments and this binding of the first call to the created function.
Subsequent calls will return a promise that resolves with the same value or rejects with the same reason as the promise returned
by the created function.