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