mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-18 10:52:26 +00:00
34 lines
663 B
Nim
34 lines
663 B
Nim
when (NimMajor, NimMinor) < (1, 4):
|
|
{.push raises: [Defect].}
|
|
else:
|
|
{.push raises: [].}
|
|
|
|
import
|
|
chronos,
|
|
chronicles
|
|
import
|
|
../../../protocol/waku_relay,
|
|
../../../protocol/waku_message,
|
|
../../message_cache
|
|
|
|
export message_cache
|
|
|
|
|
|
##### TopicCache
|
|
|
|
type TopicCacheResult*[T] = MessageCacheResult[T]
|
|
|
|
type TopicCache* = MessageCache[PubSubTopic]
|
|
|
|
|
|
##### Message handler
|
|
|
|
type TopicCacheMessageHandler* = SubscriptionHandler
|
|
|
|
proc messageHandler*(cache: TopicCache): TopicCacheMessageHandler =
|
|
|
|
let handler = proc(pubsubTopic: string, msg: WakuMessage): Future[void] {.async, closure.} =
|
|
cache.addMessage(PubSubTopic(pubsubTopic), msg)
|
|
|
|
handler
|