UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

1 lines • 2.49 kB
{"version":3,"file":"createLatestComputation.js","names":[],"sources":["esm/background/createLatestComputation.js"],"sourcesContent":["function createLatestComputation(definition, changed) {\n const executor = definition.createExecutor();\n let revision = 0;\n let disposed = false;\n let computing = false;\n let waiting = null;\n let result = null;\n const isCurrent = (value) => !disposed && value === revision;\n async function drain() {\n computing = true;\n while (!disposed && waiting) {\n const request = waiting;\n waiting = null;\n try {\n const computed = await executor.execute(request, isCurrent);\n if (computed?.revision === request.revision && isCurrent(request.revision)) {\n result = computed;\n changed({ phase: \"ready\", result: computed });\n }\n } catch (error) {\n if (isCurrent(request.revision))\n changed({\n phase: \"failed\",\n revision: request.revision,\n error: error instanceof Error ? error : new Error(String(error))\n });\n }\n }\n computing = false;\n }\n return {\n update(input) {\n if (disposed) return;\n revision++;\n result = null;\n waiting = { revision, input };\n changed({ phase: \"computing\", revision });\n if (!computing) void drain();\n },\n getCurrent: () => result,\n dispose() {\n if (disposed) return;\n disposed = true;\n result = null;\n waiting = null;\n executor.dispose();\n }\n };\n}\nexport {\n createLatestComputation\n};\n//# sourceMappingURL=createLatestComputation.js.map\n"],"mappings":";AAAA,SAAS,wBAAwB,YAAY,SAAS;CACpD,MAAM,WAAW,WAAW,eAAe;CAC3C,IAAI,WAAW;CACf,IAAI,WAAW;CACf,IAAI,YAAY;CAChB,IAAI,UAAU;CACd,IAAI,SAAS;CACb,MAAM,aAAa,UAAU,CAAC,YAAY,UAAU;CACpD,eAAe,QAAQ;EACrB,YAAY;EACZ,OAAO,CAAC,YAAY,SAAS;GAC3B,MAAM,UAAU;GAChB,UAAU;GACV,IAAI;IACF,MAAM,WAAW,MAAM,SAAS,QAAQ,SAAS,SAAS;IAC1D,IAAI,UAAU,aAAa,QAAQ,YAAY,UAAU,QAAQ,QAAQ,GAAG;KAC1E,SAAS;KACT,QAAQ;MAAE,OAAO;MAAS,QAAQ;KAAS,CAAC;IAC9C;GACF,SAAS,OAAO;IACd,IAAI,UAAU,QAAQ,QAAQ,GAC5B,QAAQ;KACN,OAAO;KACP,UAAU,QAAQ;KAClB,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;IACjE,CAAC;GACL;EACF;EACA,YAAY;CACd;CACA,OAAO;EACL,OAAO,OAAO;GACZ,IAAI,UAAU;GACd;GACA,SAAS;GACT,UAAU;IAAE;IAAU;GAAM;GAC5B,QAAQ;IAAE,OAAO;IAAa;GAAS,CAAC;GACxC,IAAI,CAAC,WAAW,KAAK,MAAM;EAC7B;EACA,kBAAkB;EAClB,UAAU;GACR,IAAI,UAAU;GACd,WAAW;GACX,SAAS;GACT,UAAU;GACV,SAAS,QAAQ;EACnB;CACF;AACF"}