import { _ as __awaiter } from '../tslib.es6-o7ymTKWv.js';
import { isPromise } from './is-type.js';

function hookAsyncData(init) {
    const initPromise = isPromise(init) ? init : init();
    let data = undefined;
    const getData = () => __awaiter(this, void 0, void 0, function* () {
        if (data !== undefined) {
            return data;
        }
        return initPromise;
    });
    return {
        getData,
        setData: (newData) => {
            data = newData;
        },
        setDataInFn: (fn) => __awaiter(this, void 0, void 0, function* () {
            const nowData = yield getData();
            data = fn(nowData);
        }),
    };
}

export { hookAsyncData };
//# sourceMappingURL=hooks.js.map
