146
146
147
147
PubsubTicket * = ref object
148
148
topic* : string
149
- handler* : P2PPubSubCallback
149
+ handler* : P2PPubSubCallback2
150
150
transp* : StreamTransport
151
151
152
152
PubSubMessage * = object
@@ -162,8 +162,10 @@ type
162
162
.}
163
163
P2PPubSubCallback * = proc (
164
164
api: DaemonAPI , ticket: PubsubTicket , message: PubSubMessage
165
- ): Future [bool ] {.gcsafe , async : (raises: [CatchableError ]).}
166
-
165
+ ): Future [bool ] {.gcsafe , raises : [CatchableError ].}
166
+ P2PPubSubCallback2 * = proc (
167
+ api: DaemonAPI , ticket: PubsubTicket , message: PubSubMessage
168
+ ): Future [bool ] {.async : (raises: [CatchableError ]).}
167
169
DaemonError * = object of LPError
168
170
DaemonRemoteError * = object of DaemonError
169
171
DaemonLocalError * = object of DaemonError
@@ -1480,7 +1482,7 @@ proc pubsubLoop(
1480
1482
break
1481
1483
1482
1484
proc pubsubSubscribe * (
1483
- api: DaemonAPI , topic: string , handler: P2PPubSubCallback
1485
+ api: DaemonAPI , topic: string , handler: P2PPubSubCallback2
1484
1486
): Future [PubsubTicket ] {.
1485
1487
async : (
1486
1488
raises:
@@ -1508,6 +1510,18 @@ proc pubsubSubscribe*(
1508
1510
await api.closeConnection (transp)
1509
1511
raise exc
1510
1512
1513
+ proc pubsubSubscribe * (
1514
+ api: DaemonAPI , topic: string , handler: P2PPubSubCallback
1515
+ ): Future [PubsubTicket ] {.
1516
+ async : (raises: [CatchableError ]), deprecated : " Use P2PPubSubCallback2 instead"
1517
+ .} =
1518
+ proc wrap (
1519
+ api: DaemonAPI , ticket: PubsubTicket , message: PubSubMessage
1520
+ ): Future [bool ] {.async : (raises: [CatchableError ]).} =
1521
+ await handler (api, ticket, message)
1522
+
1523
+ await pubsubSubscribe (api, topic, wrap)
1524
+
1511
1525
proc shortLog * (pinfo: PeerInfo ): string =
1512
1526
# # Get string representation of ``PeerInfo`` object.
1513
1527
result = newStringOfCap (128 )
0 commit comments