mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-14 08:57:14 +00:00
fix/message-notification-descriptive (#327)
* moved * added docs * Update message_notifier.nim * Update waku_types.nim
This commit is contained in:
parent
8203f30099
commit
3242b0020b
@ -3,11 +3,26 @@ import
|
|||||||
chronos,
|
chronos,
|
||||||
../waku_types
|
../waku_types
|
||||||
|
|
||||||
# The Message Notification system is a method to notify various protocols
|
## The Message Notification system is a method to notify various protocols
|
||||||
# running on a node when a new message was received.
|
## running on a node when a new message was received.
|
||||||
#
|
#
|
||||||
# Protocols can subscribe to messages of specific topics, then when one is received
|
## Protocols can subscribe to messages of specific topics, then when one is received
|
||||||
# The notification handler function will be called.
|
## The notification handler function will be called.
|
||||||
|
##
|
||||||
|
## This works as follows:
|
||||||
|
##
|
||||||
|
## .. code-block::
|
||||||
|
## var topic = "foo"
|
||||||
|
##
|
||||||
|
## proc handle(topic: string, msg: WakuMessage) {.async.} =
|
||||||
|
## info "new message", msg = msg
|
||||||
|
##
|
||||||
|
## MessageNotificationSubscription.init(@[topic], handle)
|
||||||
|
##
|
||||||
|
## var subscriptions = newTable[string, MessageNotificationSubscription]()
|
||||||
|
## subscriptions["identifier"] = subscription
|
||||||
|
##
|
||||||
|
## await subscriptions.notify(topic, WakuMessage(payload: @[byte 1, 2, 3], contentTopic: ContentTopic(1)))
|
||||||
proc subscribe*(subscriptions: MessageNotificationSubscriptions, name: string, subscription: MessageNotificationSubscription) =
|
proc subscribe*(subscriptions: MessageNotificationSubscriptions, name: string, subscription: MessageNotificationSubscription) =
|
||||||
subscriptions.add(name, subscription)
|
subscriptions.add(name, subscription)
|
||||||
|
|
||||||
|
@ -38,11 +38,13 @@ type
|
|||||||
MessageNotificationHandler* = proc(topic: string, msg: WakuMessage): Future[
|
MessageNotificationHandler* = proc(topic: string, msg: WakuMessage): Future[
|
||||||
void] {.gcsafe, closure.}
|
void] {.gcsafe, closure.}
|
||||||
|
|
||||||
MessageNotificationSubscriptions* = TableRef[string, MessageNotificationSubscription]
|
MessageNotificationSubscriptionIdentifier* = string
|
||||||
|
|
||||||
MessageNotificationSubscription* = object
|
MessageNotificationSubscription* = object
|
||||||
topics*: seq[string] # @TODO TOPIC
|
topics*: seq[string] # @TODO TOPIC
|
||||||
handler*: MessageNotificationHandler
|
handler*: MessageNotificationHandler
|
||||||
|
|
||||||
|
MessageNotificationSubscriptions* = TableRef[MessageNotificationSubscriptionIdentifier, MessageNotificationSubscription]
|
||||||
|
|
||||||
FilterRequest* = object
|
FilterRequest* = object
|
||||||
contentFilters*: seq[ContentFilter]
|
contentFilters*: seq[ContentFilter]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user