Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bentocache/src/cache/factory_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class FactoryRunner {
* And immediately return the fallback value
*/
if (options.shouldSwr(hasGracedValue)) {
this.#runFactory({ key, factory, options, lockReleaser, isBackground: true })
this.#runFactory({ key, factory, options, lockReleaser, isBackground: true, gracedValue })
throw new errors.E_FACTORY_SOFT_TIMEOUT(key)
}

Expand Down
7 changes: 5 additions & 2 deletions packages/bentocache/tests/cache/factory_context.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,17 @@ test.group('Factory Context', () => {

await sleep(100)

let gracedEntryValue;

const r1 = await cache.getOrSet({
key: 'foo',
factory: ({ gracedEntry }) => {
assert.deepEqual(gracedEntry?.value, 'bar')
return gracedEntry?.value
gracedEntryValue = gracedEntry?.value
return gracedEntryValue
},
})

assert.deepEqual(gracedEntryValue, 'bar')
assert.deepEqual(r1, 'bar')
})
})