Skip to content

Commit

Permalink
chore: callback compatibility for daemonapi
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Feb 19, 2025
1 parent b5f657e commit a978660
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions libp2p/daemon/daemonapi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ type

PubsubTicket* = ref object
topic*: string
handler*: P2PPubSubCallback
handler*: P2PPubSubCallback2
transp*: StreamTransport

PubSubMessage* = object
Expand All @@ -162,8 +162,10 @@ type
.}
P2PPubSubCallback* = proc(
api: DaemonAPI, ticket: PubsubTicket, message: PubSubMessage
): Future[bool] {.async: (raises: [CatchableError]).}

): Future[bool] {.gcsafe, raises: [CatchableError].}
P2PPubSubCallback2* = proc(
api: DaemonAPI, ticket: PubsubTicket, message: PubSubMessage
): Future[bool] {.async:(raises: [CatchableError]).}
DaemonError* = object of LPError
DaemonRemoteError* = object of DaemonError
DaemonLocalError* = object of DaemonError
Expand Down Expand Up @@ -1480,7 +1482,7 @@ proc pubsubLoop(
break

proc pubsubSubscribe*(
api: DaemonAPI, topic: string, handler: P2PPubSubCallback
api: DaemonAPI, topic: string, handler: P2PPubSubCallback2
): Future[PubsubTicket] {.
async: (
raises:
Expand Down Expand Up @@ -1508,6 +1510,13 @@ proc pubsubSubscribe*(
await api.closeConnection(transp)
raise exc

proc pubsubSubscribe*(
api: DaemonAPI, topic: string, handler: P2PPubSubCallback
): Future[PubsubTicket] {.async: (raises: [CatchableError]), deprecated: "Use P2PPubSubCallback2 instead".} =
proc wrap(api: DaemonAPI, ticket: PubsubTicket, message: PubSubMessage): Future[bool] {.async:(raises: [CatchableError]).} =
await handler(api, ticket, message)
await pubsubSubscribe(api, topic, wrap)

proc shortLog*(pinfo: PeerInfo): string =
## Get string representation of ``PeerInfo`` object.
result = newStringOfCap(128)
Expand Down

0 comments on commit a978660

Please sign in to comment.