Skip to content

Commit e173ca3

Browse files
committed
examples sleep to eliminate cpu load
1 parent a50a43d commit e173ca3

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

examples/chatclient.nim

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import netty
1+
import netty, os
22

33
var client = newReactor()
44
var connection = client.connect("127.0.0.1", 2001)
@@ -17,3 +17,4 @@ while true:
1717
let line = readLine(stdin)
1818
if line.len > 0:
1919
client.send(connection, name & ":" & line)
20+
sleep(1)

examples/chatclientthreads.nim

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# nim c -r --threads:on --tlsEmulation:off tests\chatclientthreads
22

3-
import netty, terminal
3+
import netty, os, terminal
44

55
var client = newReactor()
66
var connection = client.connect("127.0.0.1", 2001)
@@ -60,3 +60,4 @@ while true:
6060

6161
# reset character
6262
singleChar = char(0)
63+
sleep(1)

examples/chatserver.nim

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import netty
1+
import netty, os
22

33
var server = newReactor("127.0.0.1", 2001)
44
echo "Listenting for UDP on 127.0.0.1:2001"
@@ -13,3 +13,4 @@ while true:
1313
# send msg data to all connections
1414
for connection in server.connections:
1515
server.send(connection, msg.data)
16+
sleep(1)

examples/client.nim

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import netty
1+
import netty, os
22

33
# create connection
44
var client = newReactor()
@@ -14,3 +14,4 @@ while true:
1414
for msg in client.messages:
1515
# print message data
1616
echo "GOT MESSAGE: ", msg.data
17+
sleep(1)

examples/server.nim

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import netty
1+
import netty, os
22

33
# listen for a connection on localhost port 1999
44
var server = newReactor("127.0.0.1", 1999)
@@ -13,3 +13,4 @@ while true:
1313
echo "GOT MESSAGE: ", msg.data
1414
# echo message back to the client
1515
server.send(msg.conn, "you said:" & msg.data)
16+
sleep(1)

0 commit comments

Comments
 (0)