Proper use of sequences in coroutine tests

This commit is contained in:
Rokas Kupstys 2017-02-24 10:51:54 +02:00
commit 9df0000621
2 changed files with 8 additions and 11 deletions

View file

@ -1,21 +1,20 @@
import coro import coro
var var
stackCheckValue = 1100220033 stackCheckValue = 1100220033
numbers = newSeq[int](10) numbers = newSeqOfCap[int](10)
i = 0
proc testExceptions(id: int, sleep: float) = proc testExceptions(id: int, sleep: float) =
try: try:
numbers[i] = id; inc(i) numbers.add(id)
suspend(sleep) suspend(sleep)
numbers[i] = id; inc(i) numbers.add(id)
raise (ref ValueError)() raise (ref ValueError)()
except: except:
numbers[i] = id; inc(i) numbers.add(id)
suspend(sleep) suspend(sleep)
numbers[i] = id; inc(i) numbers.add(id)
suspend(sleep) suspend(sleep)
numbers[i] = id; inc(i) numbers.add(id)
start(proc() = testExceptions(1, 0.01)) start(proc() = testExceptions(1, 0.01))
start(proc() = testExceptions(2, 0.011)) start(proc() = testExceptions(2, 0.011))

View file

@ -3,8 +3,7 @@ include system/timers
var var
stackCheckValue = 1100220033 stackCheckValue = 1100220033
numbers = newSeq[int](10) numbers = newSeqOfCap[int](10)
i = 0
iterator theIterator(id: int, sleep: float): int = iterator theIterator(id: int, sleep: float): int =
for i in 0..<5: for i in 0..<5:
@ -13,8 +12,7 @@ iterator theIterator(id: int, sleep: float): int =
proc theCoroutine(id: int, sleep: float32) = proc theCoroutine(id: int, sleep: float32) =
for n in theIterator(id, sleep): for n in theIterator(id, sleep):
numbers[i] = n numbers.add(n)
inc(i)
var start = getTicks() var start = getTicks()
start(proc() = theCoroutine(1, 0.01)) start(proc() = theCoroutine(1, 0.01))