Actors example Thread ring fixes
authorBlackMinou <romain.chanoir@viacesi.fr>
Wed, 29 Mar 2017 18:54:12 +0000 (14:54 -0400)
committerBlackMinou <romain.chanoir@viacesi.fr>
Wed, 29 Mar 2017 19:26:35 +0000 (15:26 -0400)
Signed-off-by: BlackMinou <romain.chanoir@viacesi.fr>

lib/actors/examples/thread-ring/thread_ring.nit

index 2da490d..18da93a 100644 (file)
@@ -33,26 +33,24 @@ class ThreadRing
 
        # Receive a token, then send it to `next` unless its value is `0`
        fun send_token(message: Int) do
-               if message == 0 then
-                       print id
-               end
-               if message >= 1 then
-                       next.async.send_token(message - 1)
-               end
+               if message == 0 then print id
+               if message >= 1 then next.async.send_token(message - 1)
        end
 end
 
+redef class Sys
+       # numbers of actors to create the ring
+       var nb_actors = 503
+end
+
 var first = new ThreadRing(1)
 var current = new ThreadRing(2)
 first.next = current
-for i in [3..503] do
+for i in [3..nb_actors] do
        var t = new ThreadRing(i)
        current.next = t
        current = t
 end
 current.next = first
-if args.is_empty then
-       first.send_token(1000)
-else
-       first.send_token(args[0].to_i)
-end
+var n = if args.is_empty then 1000 else args[0].to_i
+first.send_token(n)