Successus has joined #jruby
sagax has quit [Ping timeout: 248 seconds]
<byteit101[m]> Something like this? (lots of issues, but simple back/forth is working) class VFiber; def initialize &blk; vf = self; @in=false; @future=java.util.concurrent.CompletableFuture.new; java.lang.Thread.ofVirtual.start{@future.get; VFiber.current = vf; begin; @future.complete blk.call; ensure; vf.dead!; end;}; @alive = true; end; class << self; attr_accessor :current; def yield *args; @current.yield *args; end; end; def yield *args; raise
<byteit101[m]> "backwards" unless @in; @in = false; oldcf, @future = @future, java.util.concurrent.CompletableFuture.new; VFiber.current = self; oldcf.complete args; return @future.get; end; def resume *args; raise "forwards" if @in; @in = true;oldcf, @future = @future, java.util.concurrent.CompletableFuture.new; VFiber.current = self; oldcf.complete args; return @future.get; end; def alive?; @alive; end; def dead!; @alive = false; end; end
<byteit101[m]> jruby-9.3.4.0 :007 > f = VFiber.new { VFiber.yield 1; VFiber.yield 2}
<byteit101[m]> => #<VFiber:0x5b7a7f33 @alive=true, @in=false, @future=#<Java::JavaUtilConcurrent::CompletableFuture:0x790da477>>
<byteit101[m]> jruby-9.3.4.0 :008 > f.resume
<byteit101[m]> => [1]
<headius> Ha looks like a good start
<byteit101[m]> Literally just a 5 minute one liner :)
Successus has quit []
Successus has joined #jruby
sagax has joined #jruby
Successus has quit []