[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[fibers] 02 generator

Yielding execution will resume back in the fiber right where you left off.
You can also pass values back and forth through #yield: and #run:.
The node event loop is never blocked while this test is running.

| inc count |
inc := Fiber @ [:start| | total |
	total := start.
	[true] whileTrue: [
		total := total + (Fiber yield: total)
	]
].
count := inc run: 1.
[count <=10] whileTrue: [
	count := inc run: 1.
	self print: 'step ',count
].
self print: 'done.'