S
Shay Hawkins
Hello,
I'm relatively new to advanced Ruby programming, and I seem to be in
need of a "dummy" IO object that does nothing except allowing reading
and writing to it. (I suppose it could do more, but I'd like to keep it
as simple as possible.) What I mean is, I need to use a select statement
to check an array two IO objects that could have data to be read.
However, in other threads running, I will be needing to push data to
these objects.
I'm using Windows Vista, and what I've found out about IO.pipe doesn't
seem to work like I intended - at least, not on my operating system.
Here's an example of what I'm trying to do:
$objectA = ???
$objectB = ???
Thread.new() do
$objectA.puts("stuff")
sleep(10)
end
Thread.new() do
$objectB.puts("stuff")
sleep(15)
end
while(1)
ready = select([$objectA,$objectB])
next if(ready == nil)
for object in ready[0]
if(object == $objectA)
puts("10 milliseconds have passed in the first thread.")
puts(">> with message: #{object.gets()}")
elsif(object == $objectB)
puts("15 milliseconds have passed in the second thread.")
puts(">> with message: #{object.gets()}")
end
end
end
Does anyone know of a way I could accomplish this? If I'm not explaining
what I'm trying to do clearly enough, just ask what more you'd like to
know. Also, please don't comment on any of the conventions I use, unless
it directly pertains to the IO question - the above is an example, and
barely resembles the actual code.
I'm relatively new to advanced Ruby programming, and I seem to be in
need of a "dummy" IO object that does nothing except allowing reading
and writing to it. (I suppose it could do more, but I'd like to keep it
as simple as possible.) What I mean is, I need to use a select statement
to check an array two IO objects that could have data to be read.
However, in other threads running, I will be needing to push data to
these objects.
I'm using Windows Vista, and what I've found out about IO.pipe doesn't
seem to work like I intended - at least, not on my operating system.
Here's an example of what I'm trying to do:
$objectA = ???
$objectB = ???
Thread.new() do
$objectA.puts("stuff")
sleep(10)
end
Thread.new() do
$objectB.puts("stuff")
sleep(15)
end
while(1)
ready = select([$objectA,$objectB])
next if(ready == nil)
for object in ready[0]
if(object == $objectA)
puts("10 milliseconds have passed in the first thread.")
puts(">> with message: #{object.gets()}")
elsif(object == $objectB)
puts("15 milliseconds have passed in the second thread.")
puts(">> with message: #{object.gets()}")
end
end
end
Does anyone know of a way I could accomplish this? If I'm not explaining
what I'm trying to do clearly enough, just ask what more you'd like to
know. Also, please don't comment on any of the conventions I use, unless
it directly pertains to the IO question - the above is an example, and
barely resembles the actual code.