Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Ruby 1.9 - equivalent of Fiber.current ?
Suraj Kurapati
3/2/2008 7:27:00 AM
Hello,
Is it possible to detect whether a method is being called by a Fiber in
Ruby 1.9?
I hoped that there would be a Fiber.current method (just like
Thread.current), but that does not exist:
>> Fiber.methods(false).sort
=> [:new, :yield]
I need to know this information for a method that's part of an
application-level thread/fiber/task scheduler for my Ruby-VPI
project[1]. This method must either (1) run Fiber.yield (if called by a
Fiber) or (2) relay control from the Ruby interpreter to a C extension.
Thanks for your consideration.
[1]
http://ruby-vpi.rub...
--
Posted via
http://www.ruby-...
.
2 Answers
Suraj Kurapati
3/2/2008 7:34:00 AM
0
Suraj Kurapati wrote:
> Is it possible to detect whether a method
> is being called by a Fiber in Ruby 1.9?
Heh, I should have just tried it:
>> Fiber.yield
FiberError: can't yield from root fiber
So the solution is:
begin
# inside a fiber
Fiber.yield
rescue FiberError
# not inside a fiber...
end
But I suppose Fiber.yield could raise FiberError for other reasons...
is there a better way to do this detection?
--
Posted via
http://www.ruby-...
.
Suraj Kurapati
3/2/2008 5:06:00 PM
0
ts wrote:
> vgs% ruby -rfiber -e 'p Fiber.methods(false)'
> [:new, :yield, :current]
> vgs%
Aha! We need to require 'fiber' in order
to get the Fiber.current method. Thanks!
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Ruby 1.9 - equivalent of Fiber.current ?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password