1 ///
2 module sfw.func;
3 
4 import sfw.fiber;
5 import std.datetime : Clock, Duration;
6 import core.thread : Thread, Fiber;
7 
8 /// set `nextTime` if fiber is `SFWFiber`
9 void sleep(Duration d)
10 {
11     if (auto f = Fiber.getThis())
12     {
13         auto sfwf = cast(SFWFiber)f;
14         auto nt = Clock.currStdTime + d.total!"hnsecs";
15         if (sfwf !is null)
16         {
17             sfwf.nextTime = nt;
18             sfwf.yield();
19         }
20         else while (Clock.currStdTime < nt) sfwf.yield();
21     }
22     else Thread.sleep(d);
23 }
24 
25 ///
26 void yield()
27 {
28     if (auto f = Fiber.getThis()) f.yield();
29     else Thread.yield();
30 }