@@ -29,11 +29,12 @@ export interface Cached<T> extends Readable<T> {
|
|||||||
export function cached<T>(normal: T, init: () => Promise<T>): Cached<T> {
|
export function cached<T>(normal: T, init: () => Promise<T>): Cached<T> {
|
||||||
const store = writable<T>(normal);
|
const store = writable<T>(normal);
|
||||||
const future = new Promise<T>((resolve) => {
|
const future = new Promise<T>((resolve) => {
|
||||||
let f = true;
|
let f = false;
|
||||||
store.subscribe((value) => {
|
store.subscribe((value) => {
|
||||||
if (f) {
|
if (f) {
|
||||||
f = false;
|
|
||||||
resolve(value);
|
resolve(value);
|
||||||
|
} else {
|
||||||
|
f = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user