[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet-nim] 53/61: restructure groupchat application
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet-nim] 53/61: restructure groupchat application |
Date: |
Sat, 13 Apr 2019 13:36:28 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnunet-nim.
commit b95e5ca8c1512c1b94d537f28ddc60f90c17b6b0
Author: lurchi <address@hidden>
AuthorDate: Sat Aug 18 01:46:47 2018 +0200
restructure groupchat application
---
examples/groupchat.nim | 38 +++++++++++++++++---------------------
1 file changed, 17 insertions(+), 21 deletions(-)
diff --git a/examples/groupchat.nim b/examples/groupchat.nim
index 26f9848..93d4323 100644
--- a/examples/groupchat.nim
+++ b/examples/groupchat.nim
@@ -21,21 +21,17 @@ proc processClientMessages(channel: ref CadetChannel,
chat.publish(message = message, sender = channel)
proc processServerMessages(channel: ref CadetChannel) {.async.} =
- let inputFile = openAsync("/dev/stdin", fmRead)
- var inputFuture = inputFile.readline()
- var messageFuture = channel.messages.read()
while true:
- await inputFuture or messageFuture
- if inputFuture.finished():
- let input = inputFuture.read()
- channel.sendMessage(input)
- inputFuture = inputFile.readline()
- else:
- let (hasData, message) = messageFuture.read()
- if not hasData:
- break
- echo getDateStr()," ",getClockStr()," ",message
- messageFuture = channel.messages.read()
+ let (hasData, message) = await channel.messages.read()
+ if not hasData:
+ shutdownGnunetApplication()
+ return
+ echo getDateStr()," ",getClockStr()," ",message
+
+proc processInput(inputFile: AsyncFile, channel: ref CadetChannel) {.async.} =
+ while true:
+ let input = await inputFile.readline()
+ channel.sendMessage(input)
proc firstTask(gnunetApp: ref GnunetApplication,
server: string,
@@ -44,8 +40,10 @@ proc firstTask(gnunetApp: ref GnunetApplication,
var chat = new(Chat)
chat.channels = newSeq[ref CadetChannel]()
if not server.isNil():
+ let inputFile = openAsync("/dev/stdin", fmRead)
let channel = cadet.createChannel(server, port)
- processServerMessages(channel).addCallback(shutdownGnunetApplication)
+ await processServerMessages(channel) or processInput(inputFile, channel)
+ inputFile.close()
else:
let cadetPort = cadet.openPort(port)
while true:
@@ -80,12 +78,10 @@ proc main() =
assert(false)
var gnunetApp = initGnunetApplication(configfile)
asyncCheck firstTask(gnunetApp, server, port)
- try:
- while true:
- poll(gnunetApp.millisecondsUntilTimeout())
- gnunetApp.doWork()
- except ValueError:
- echo "quitting"
+ while hasPendingOperations():
+ poll(gnunetApp.millisecondsUntilTimeout())
+ gnunetApp.doWork()
+ echo "quitting"
main()
GC_fullCollect()
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnunet-nim] 32/61: Revert "use ref object where we only use heap allocation", (continued)
- [GNUnet-SVN] [gnunet-nim] 32/61: Revert "use ref object where we only use heap allocation", gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 26/61: first try sending messages from stdin, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 40/61: fix bug (application hangs when a peer disconnects); fixes & simplifications, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 34/61: add shutdown logic (allows GNUnet to shutdown on signals), gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 46/61: groupchat.nim: fix typo in echo message, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 25/61: fix sending messages, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 43/61: Merge branch 'master' of ssh://gnunet.org/gnunet-nim, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 21/61: add GNUnet configs and scripts for testing, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 56/61: gnunet_nim.nim: fix import paths to point to parent dir, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 37/61: disconnect from the cadet service when CadetHandle is destroyed, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 53/61: restructure groupchat application,
gnunet <=
- [GNUnet-SVN] [gnunet-nim] 44/61: add peer ID string functions, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 45/61: use peer IDs as chat identifiers, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 48/61: Makefile to clean the build., gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 52/61: workaround for missing notification about disconnected cadet channels, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 09/61: fix compilation, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 60/61: Start of a nimble file, should probably drop nake later on., gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 49/61: added date and time string to output, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 10/61: fix compilation (2), gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 23/61: receiving of cadet messages possible now, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 51/61: Merge branch 'master' of ssh://gnunet.org/gnunet-nim, gnunet, 2019/04/13