Reactor, fiber scheduler and async in Ruby 3.0

Adam D. Ruppe destructionator at gmail.com
Thu Dec 31 16:32:17 UTC 2020


On Thursday, 31 December 2020 at 14:53:52 UTC, Jacob Carlborg 
wrote:
> The existing IO related methods in the core/standard library 
> has been updated to be fiber scheduler aware. That basically 
> means that if there is no fiber scheduler set, the IO 
> operations will be blocking. If a fiber scheduler has been set, 
> they will instead be non-blocking.

omg that's a really good idea.

Over the weekend I wrote a Phobos subclass 
<http://dpldocs.info/experimental-docs/arsd.fibersocket.html> 
that does fiber sockets. Pretty simple code really.

But the connect* family of functions just assert they are inside 
a fiber right now.... but since they implement the same Socket 
interface, I could just do `if(fiber.getThis is null) return new 
Socket; else return new FiberSocket` and do the same behavior 
ruby is showing.

Very convenient...

(the difference between this and ruby though is i still have a 
FiberManager class you use as the socket factory, whereas I 
suppose they just made the existing methods return appropriate 
classes. Or heck I could even just make the overridden methods be 
like `if(thisFiber is null) super.receive(); else { ... }`. 
That'd be reasonably acceptable too. Heck even Phobos itself 
could potentially do that.)


More information about the Digitalmars-d mailing list