mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-05-24 03:10:03 +00:00
chore: add deprecation notice to utils module. move heartbeat to common
This commit is contained in:
parent
81d03558b1
commit
e8dceb2aa6
@ -1,13 +1,19 @@
|
|||||||
|
## An extension wrapper around nim-chronos
|
||||||
when (NimMajor, NimMinor) < (1, 4):
|
when (NimMajor, NimMinor) < (1, 4):
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
else:
|
else:
|
||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import sequtils
|
import
|
||||||
import chronos, chronicles
|
chronos,
|
||||||
|
chronicles
|
||||||
|
|
||||||
|
export chronos
|
||||||
|
|
||||||
|
|
||||||
|
## Extension methods
|
||||||
|
|
||||||
# Taken from: https://github.com/status-im/nim-libp2p/blob/master/libp2p/utils/heartbeat.nim
|
# Taken from: https://github.com/status-im/nim-libp2p/blob/master/libp2p/utils/heartbeat.nim
|
||||||
|
|
||||||
template heartbeat*(name: string, interval: Duration, body: untyped): untyped =
|
template heartbeat*(name: string, interval: Duration, body: untyped): untyped =
|
||||||
var nextHeartbeat = Moment.now()
|
var nextHeartbeat = Moment.now()
|
||||||
while true:
|
while true:
|
||||||
@ -19,11 +25,12 @@ template heartbeat*(name: string, interval: Duration, body: untyped): untyped =
|
|||||||
let
|
let
|
||||||
delay = now - nextHeartbeat
|
delay = now - nextHeartbeat
|
||||||
itv = interval
|
itv = interval
|
||||||
|
|
||||||
if delay > itv:
|
if delay > itv:
|
||||||
info "Missed multiple heartbeats", heartbeat = name,
|
info "Missed multiple heartbeats", heartbeat = name, delay = delay, hinterval = itv
|
||||||
delay = delay, hinterval = itv
|
|
||||||
else:
|
else:
|
||||||
debug "Missed heartbeat", heartbeat = name,
|
debug "Missed heartbeat", heartbeat = name, delay = delay, hinterval = itv
|
||||||
delay = delay, hinterval = itv
|
|
||||||
nextHeartbeat = now + itv
|
nextHeartbeat = now + itv
|
||||||
|
|
||||||
await sleepAsync(nextHeartbeat - now)
|
await sleepAsync(nextHeartbeat - now)
|
||||||
6
waku/common/utils/DEPRECATION_NOTICE.md
Normal file
6
waku/common/utils/DEPRECATION_NOTICE.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# :warning: DEPRECATION NOTICE :warning:
|
||||||
|
|
||||||
|
The `utils` module has been marked as deprecated.
|
||||||
|
This package submodules are planned to be moved to different modules.
|
||||||
|
|
||||||
|
**No new sub-modules must be added to this folder.**
|
||||||
@ -12,9 +12,9 @@ import
|
|||||||
libp2p/multistream,
|
libp2p/multistream,
|
||||||
libp2p/muxers/muxer
|
libp2p/muxers/muxer
|
||||||
import
|
import
|
||||||
|
../../../common/nimchronos,
|
||||||
../../waku_relay,
|
../../waku_relay,
|
||||||
../../utils/peers,
|
../../utils/peers,
|
||||||
../../utils/heartbeat,
|
|
||||||
./peer_store/peer_storage,
|
./peer_store/peer_storage,
|
||||||
./waku_peer_store
|
./waku_peer_store
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user