class Xasin::Waitpoint

Attributes

lastArgument[R]

Public Class Methods

new() click to toggle source
# File lib/mqtt/Waitpoint.rb, line 7
def initialize()
        @waitThreads = Array.new();
        @fireID = 0;
        @lastArgument = Array.new();
end

Public Instance Methods

fire(args = nil) click to toggle source
# File lib/mqtt/Waitpoint.rb, line 13
def fire(args = nil)
        @fireID += 1
        @lastArgument = args;
        @waitThreads.each do |t|
                t.run();
        end
end
wait(seconds = nil, allow_run: false) click to toggle source
# File lib/mqtt/Waitpoint.rb, line 21
def wait(seconds = nil, allow_run: false)
        pausedID = @fireID;
        @waitThreads << Thread.current

        timed_out = false;

        begin
                Timeout::timeout(seconds) {
                        if(allow_run) then
                                Thread.stop();
                        else
                                Thread.stop() until pausedID != @fireID;
                        end
                }
        rescue Timeout::Error
                timed_out = true;
        ensure
                @waitThreads.delete(Thread.current);
        end

        return timed_out, @lastArgument;
end