This repository was archived by the owner on Apr 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 41
41
SysMsg = enum
42
42
GET_NAME_REQ, GET_NAME_REP
43
43
44
- ThreadMessage* = object
44
+ ThreadMessage = object
45
45
kind: ThreadMessageKind
46
46
action: string
47
47
json: JsonNode
50
50
channel: ThreadChannelPtr
51
51
callbackId: int
52
52
53
- ThreadChannel* = Channel[ThreadMessage]
54
- ThreadChannelPtr* = ptr Channel[ThreadMessage]
53
+ ThreadChannel = Channel[ThreadMessage]
54
+ ThreadChannelPtr = ptr Channel[ThreadMessage]
55
55
56
56
ThreadActionHandler* = proc (data: JsonNode): Future[JsonNode] {.gcsafe.}
57
57
ThreadDefaultActionHandler* = proc (action: string , data: JsonNode): Future[JsonNode] {.gcsafe.}
Original file line number Diff line number Diff line change @@ -10,6 +10,12 @@ proc workerMain(proxy: ThreadProxy) {.thread.} =
10
10
proxy.onData " resend" :
11
11
asyncCheck proxy.send(" main" , " recev" , data)
12
12
13
+ proxy.onDefaultData:
14
+ return %* {
15
+ " action" : action,
16
+ " data" : data
17
+ }
18
+
13
19
asyncCheck proxy.poll()
14
20
15
21
@@ -52,6 +58,17 @@ suite "threadproxy":
52
58
discard waitFor proxy.ask(" worker1" , " ping" , % " pong" )
53
59
assert done
54
60
61
+ test " onDefaultData" :
62
+ let proxy = newMainThreadProxy(" main" )
63
+ asyncCheck proxy.poll()
64
+
65
+ proxy.createThread(" worker1" , workerMain)
66
+
67
+ let a = waitFor proxy.ask(" worker1" , " some_unknown_action" , % " pong" )
68
+ assert a == %* {
69
+ " action" : " some_unknown_action" ,
70
+ " data" : " pong"
71
+ }
55
72
56
73
57
74
You can’t perform that action at this time.
0 commit comments