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

test[fibers] 01 sleep

This is a quick example of how you can write sleep with fibers.
Note that while sleep is blocking inside the fiber, node is able to handle other events.

| sleep |
sleep := [:ms| | fiber |
	fiber := Fiber current.
	[ fiber run ] valueDeferred: ms.
	Fiber yield
(Fiber @ [
	self print: ' about to wait ',DateTime new.
	sleep value: 1000.
	self print: ' post     wait ',DateTime new.
]) run.
self print: 'done.'