Skip to content

Commit

Permalink
chore: add deprecation notice to utils module. move heartbeat to common
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo Delgado authored Apr 19, 2023
1 parent 81d0355 commit e8dceb2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
21 changes: 14 additions & 7 deletions waku/v2/utils/heartbeat.nim → waku/common/nimchronos.nim
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
## An extension wrapper around nim-chronos
when (NimMajor, NimMinor) < (1, 4):
{.push raises: [Defect].}
else:
{.push raises: [].}

import sequtils
import chronos, chronicles
import
chronos,
chronicles

export chronos

# Taken from: https://github.com/status-im/nim-libp2p/blob/master/libp2p/utils/heartbeat.nim

## Extension methods

# Taken from: https://github.com/status-im/nim-libp2p/blob/master/libp2p/utils/heartbeat.nim
template heartbeat*(name: string, interval: Duration, body: untyped): untyped =
var nextHeartbeat = Moment.now()
while true:
Expand All @@ -19,11 +25,12 @@ template heartbeat*(name: string, interval: Duration, body: untyped): untyped =
let
delay = now - nextHeartbeat
itv = interval

if delay > itv:
info "Missed multiple heartbeats", heartbeat = name,
delay = delay, hinterval = itv
info "Missed multiple heartbeats", heartbeat = name, delay = delay, hinterval = itv
else:
debug "Missed heartbeat", heartbeat = name,
delay = delay, hinterval = itv
debug "Missed heartbeat", heartbeat = name, delay = delay, hinterval = itv

nextHeartbeat = now + itv

await sleepAsync(nextHeartbeat - now)
6 changes: 6 additions & 0 deletions waku/common/utils/DEPRECATION_NOTICE.md
Original file line number Diff line number Diff line change
@@ -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.**
2 changes: 1 addition & 1 deletion waku/v2/node/peer_manager/peer_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import
libp2p/multistream,
libp2p/muxers/muxer
import
../../../common/nimchronos,
../../waku_relay,
../../utils/peers,
../../utils/heartbeat,
./peer_store/peer_storage,
./waku_peer_store

Expand Down

0 comments on commit e8dceb2

Please sign in to comment.