diff options
author | Araq <rumpf_a@web.de> | 2011-12-31 11:18:18 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-12-31 11:18:18 +0100 |
commit | 92395568bbac524bb3f739a621e8110c60524f69 (patch) | |
tree | 1d274399381af45968d5c436009c8f4cc4559190 /lib | |
parent | 743182afd79fa3e473659e4571d500a0bcac7a5e (diff) | |
download | Nim-92395568bbac524bb3f739a621e8110c60524f69.tar.gz |
improved actors.sync
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/actors.nim | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/pure/actors.nim b/lib/pure/actors.nim index c07adfd93..d51b973b7 100644 --- a/lib/pure/actors.nim +++ b/lib/pure/actors.nim @@ -119,15 +119,25 @@ proc createActorPool*[TIn, TOut](a: var TActorPool[TIn, TOut], poolSize = 4) = proc sync*[TIn, TOut](a: var TActorPool[TIn, TOut], polling=50) = ## waits for every actor of `a` to finish with its work. Currently this is - ## implemented as polling every `polling` ms. This will change in a later + ## implemented as polling every `polling` ms and has a slight chance + ## of failing since we check for every actor to be in `ready` state and not + ## for messages still in ether. This will change in a later ## version, however. + var allReadyCount = 0 while true: var wait = false for i in 0..high(a.actors): if not a.actors[i].i.ready: wait = true + allReadyCount = 0 break - if not wait: break + if not wait: + # it's possible that some actor sent a message to some other actor but + # both appeared to be non-working as the message takes some time to + # arrive. We assume that this won't take longer than `polling` and + # simply attempt a second time and declare victory then. ;-) + inc allReadyCount + if allReadyCount > 1: break sleep(polling) proc terminate*[TIn, TOut](a: var TActorPool[TIn, TOut]) = |