Skip to content

Commit

Permalink
feat(store): Throw if store not initialized
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Bianchi <[email protected]>
  • Loading branch information
rozzilla committed Apr 23, 2024
1 parent 77ffba1 commit ce63955
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion asyncforge.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ function memo (name) {

function get () {
const store = asyncLocalStorage.getStore()
return store?.[sym]
if (!store) {
throw new Error('asyncforge store is not initialized')
}
return store[sym]
}

function set (value) {
Expand Down
4 changes: 2 additions & 2 deletions test/do-not-start-memo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('memo without start', async (t) => {
const p = tspl(t, { plan: 6 })
const a = memo()

p.deepStrictEqual(a(), undefined)
p.throws(() => a())
a.set({ value: 'bar' })
p.deepStrictEqual(a(), { value: 'bar' })

Expand Down Expand Up @@ -42,7 +42,7 @@ test('nested', async (t) => {
const p = tspl(t, { plan: 5 })
const a = memo()

p.deepStrictEqual(a(), undefined)
p.throws(() => a())
a.set({ value: 'bar' })
p.deepStrictEqual(a(), { value: 'bar' })

Expand Down

0 comments on commit ce63955

Please sign in to comment.