@jsonjoy.com/reactive-rpc
Version:
Reactive-RPC is a library for building reactive APIs over WebSocket, HTTP, and other RPCs.
19 lines • 592 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.shareByKey = void 0;
const rxjs_1 = require("rxjs");
const shareByKey = (sub) => {
const map = {};
return (key) => {
const observable = map[key];
if (observable)
return observable;
return (map[key] = (0, rxjs_1.defer)(() => sub(key)).pipe((0, rxjs_1.finalize)(() => {
delete map[key];
}), (0, rxjs_1.share)({
resetOnRefCountZero: true,
})));
};
};
exports.shareByKey = shareByKey;
//# sourceMappingURL=shareByKey.js.map
;