Skip to content

Commit

Permalink
fix: can't use setInitialize of LazyCell multi-times
Browse files Browse the repository at this point in the history
  • Loading branch information
kuuote committed Jul 9, 2024
1 parent 1c96108 commit 1791a21
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions denops/skkeleton/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class LazyCell<T> {

setInitializer(initializer: () => Promise<T>) {
this.lazyInitializer = initializer;
this.initialized = false;
}
}

Expand Down
18 changes: 18 additions & 0 deletions denops/skkeleton/util_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { assertEquals } from "./deps/std/assert.ts";
import { LazyCell } from "./util.ts";

Deno.test({
name: "LazyCell",
async fn(t) {
await t.step({
name: "can use setInitialize multi-times",
async fn() {
const cell = new LazyCell(() => 0);
cell.setInitializer(() => Promise.resolve(1));
assertEquals(await cell.get(), 1);
cell.setInitializer(() => Promise.resolve(2));
assertEquals(await cell.get(), 2);
},
});
},
});

0 comments on commit 1791a21

Please sign in to comment.