rendajs / Renda

A modern rendering engine for the web.
https://rendajs.org
MIT License
10 stars 4 forks source link

remove `once` from SingleInstancePromise #939

Open jespertheend opened 2 months ago

jespertheend commented 2 months ago

This seems useful at first. But you can really easily achieve the same effect with just a single promise:

const myAsyncObject = (async () => {
    // some code...
})();

// and then use this whenever you need it.
const theObject = await myAsyncObject;

Or if you only want to run it the moment you need it:

let promise = null;
function getAsyncObject() {
    if (promise) return promise;
    promise = (async () => {
        // some code...
    })();
    return promise;
}

We should get rid of once since it would remove a lot of unnecessary complexity.