mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-02 13:33:10 +00:00
* checked exceptions in stores
* makes asynciter as much exception safe as it gets
* introduce "SafeAsyncIter" that uses Results and limits exceptions to cancellations
* adds {.push raises: [].} to errors
* uses SafeAsyncIter in "listBlocks" and in "getBlockExpirations"
* simplifies safeasynciter (magic of auto)
* gets rid of ugly casts
* tiny fix in hte way we create raising futures in tests of safeasynciter
* Removes two more casts caused by using checked exceptions
* adds an extended explanation of one more complex SafeAsyncIter test
* adds missing "finishOnErr" param in slice constructor of SafeAsyncIter
* better fix for "Error: Exception can raise an unlisted exception: Exception" error.
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
34 lines
1011 B
Nim
34 lines
1011 B
Nim
## Nim-Codex
|
|
## Copyright (c) 2023 Status Research & Development GmbH
|
|
## Licensed under either of
|
|
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
## at your option.
|
|
## This file may not be copied, modified, or distributed except according to
|
|
## those terms.
|
|
|
|
import pkg/chronos
|
|
|
|
import codex/utils/timer
|
|
|
|
type MockTimer* = ref object of Timer
|
|
startCalled*: int
|
|
stopCalled*: int
|
|
mockInterval*: Duration
|
|
mockCallback: timer.TimerCallback
|
|
|
|
proc new*(T: type MockTimer): MockTimer =
|
|
## Create a mocked Timer instance
|
|
MockTimer(startCalled: 0, stopCalled: 0)
|
|
|
|
method start*(mockTimer: MockTimer, callback: timer.TimerCallback, interval: Duration) =
|
|
mockTimer.mockCallback = callback
|
|
mockTimer.mockInterval = interval
|
|
inc mockTimer.startCalled
|
|
|
|
method stop*(mockTimer: MockTimer) {.async: (raises: []).} =
|
|
inc mockTimer.stopCalled
|
|
|
|
method invokeCallback*(mockTimer: MockTimer) {.async, base.} =
|
|
await mockTimer.mockCallback()
|