Skip to content
This repository was archived by the owner on Apr 23, 2023. It is now read-only.

Commit e3332dd

Browse files
author
Jack Tang
committed
update comments
1 parent bf650ca commit e3332dd

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/threadproxy.nim

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,12 @@ proc on*(proxy: ThreadProxy, action: string, handler: ThreadActionHandler) =
203203
proxy.actions[action] = handler
204204
205205
proc onDefault*(proxy: ThreadProxy, handler: ThreadDefaultActionHandler) =
206-
## Set default `handler`
206+
## Set default `handler` for all unhandled action
207207
proxy.defaultAction = handler
208208
209209
template onData*(proxy: ThreadProxy, action: string, body: untyped): void =
210-
## Template version of `on`
210+
## Template version of `on`, saving you from typing `proc(data: JsonNode): Future[JsonNode] {.gcsafe,async.} = ...` every time.
211+
## The argument `data` is injected and so the name *onData*.
211212
proxy.on(
212213
action,
213214
proc(json: JsonNode): Future[JsonNode] {.gcsafe,async.} =
@@ -222,9 +223,7 @@ template onDefaultData*(proxy: ThreadProxy, body: untyped) =
222223
let data {.inject.} = j
223224
`body`
224225
225-
proc send*(proxy: ThreadProxy, target: ThreadChannelPtr, action: string, data: JsonNode): Future[void] =
226-
## Send `data` to `target` channel and then complete.
227-
## Raise MessageUndeliveredError if cannot put on to target channel.
226+
proc send(proxy: ThreadProxy, target: ThreadChannelPtr, action: string, data: JsonNode): Future[void] =
228227
result = newFuture[void]("send")
229228
let sent = target[].trySend proxy.newMessage(EMIT, action, data)
230229
if sent:
@@ -237,8 +236,7 @@ proc send*(proxy: ThreadProxy, target: ThreadChannelPtr, action: string, data: J
237236
err.sender = proxy.name
238237
result.fail(err)
239238
240-
proc ask*(proxy: ThreadProxy, target: ThreadChannelPtr, action: string, data: JsonNode = nil): Future[JsonNode] =
241-
## Send `data` to `target` channel and then wait for reply
239+
proc ask(proxy: ThreadProxy, target: ThreadChannelPtr, action: string, data: JsonNode = nil): Future[JsonNode] =
242240
let id = proxy.nextCallbackId()
243241
result = newFuture[JsonNode]("ask")
244242
proxy.jsonCallbacks[id] = result
@@ -284,12 +282,17 @@ proc getChannel*(proxy: ThreadProxy, name: string): Future[ThreadChannelPtr] =
284282
285283
286284
proc send*(proxy: ThreadProxy, target: string, action: string, data: JsonNode = nil): Future[void] {.async.} =
287-
## put one message to `target`'s channel
285+
## Send `data` to `target` channel.
286+
##
287+
## The returned future complete once the message is successfully placed on target channel.
288+
## otherwise fail with MessageUndeliveredError.
288289
let ch = await proxy.getChannel(target)
289290
await proxy.send(ch, action, data)
290291
291292
proc ask*(proxy: ThreadProxy, target: string, action: string, data: JsonNode = nil): Future[JsonNode] {.async.} =
292-
## put one message to target's channel and complete until `target`'s response
293+
## Send `data` to `target` and wait for the return.
294+
##
295+
## The returned future will complete with the result from target is received. It may fail with many kind of errors.
293296
let ch = await proxy.getChannel(target)
294297
result = await proxy.ask(ch, action, data)
295298

0 commit comments

Comments
 (0)