otter
otter copied to clipboard
[Example issue] the behaviour is not as described.
Here it will panic as the returned value is not 0 but 256. So the returned value is still from the loader instead of zero value when the loader returns error ?
// Attempt to get the key with a loader function that returns an error
value, err := cache.Get(ctx, key, otter.LoaderFunc[int, int](func(ctx context.Context, key int) (int, error) {
time.Sleep(200 * time.Millisecond) // Simulate a slow operation
// Return an error wrapped with otter.ErrNotFound
return 256, fmt.Errorf("lalala: %w", otter.ErrNotFound)
}))
// Validate the returned value and error
if value != 0 {
panic("incorrect value") // Should return zero value on error
}
Hi, it seems I just forgot to fix the example when I was writing the code for this issue. Otter always returns exactly the data that the loader returns (if it's called at all).
The example has been fixed.