Parent

Files

ZMQ::Timer

Public Class Methods

ZMQ::Timer.new(1, 2){ :fired } => ZMQ::Timer click to toggle source
Initializes a new ZMQ::Timer instance.

Examples

ZMQ::Timer.new(1, 2){ :fired }    =>  ZMQ::Timer
VALUE rb_czmq_timer_s_new(int argc, VALUE *argv, VALUE timer)
{
    VALUE delay, times, proc, callback;
    size_t timer_delay;
    zmq_timer_wrapper *tr = NULL;
    rb_scan_args(argc, argv, "21&", &delay, &times, &proc, &callback);
    if (NIL_P(proc) && NIL_P(callback)) rb_raise(rb_eArgError, "no callback given!");
    if (NIL_P(proc)) {
        rb_need_block();
    } else {
        callback = proc;
    }
    if (TYPE(delay) != T_FIXNUM && TYPE(delay) != T_FLOAT) rb_raise(rb_eTypeError, "wrong delay type %s (expected Fixnum or Float)", RSTRING_PTR(rb_obj_as_string(delay)));
    Check_Type(times, T_FIXNUM);
    timer_delay = (size_t)(((TYPE(delay) == T_FIXNUM) ? FIX2LONG(delay) : RFLOAT_VALUE(delay)) * 1000); 
    timer = Data_Make_Struct(rb_cZmqTimer, zmq_timer_wrapper, rb_czmq_mark_timer, rb_czmq_free_timer_gc, tr);
    tr->cancelled = FALSE;
    tr->delay = timer_delay;
    tr->times = FIX2INT(times);
    tr->callback = callback;
    rb_obj_call_init(timer, 0, NULL);
    return timer;
}

Public Instance Methods

call(*args) click to toggle source
Alias for: fire
cancel => nil click to toggle source
Fires a timer.

Examples

timer = ZMQ::Timer.new(1, 2){|arg| :fired }    =>  ZMQ::Timer
timer.cancel   => nil
static VALUE rb_czmq_timer_cancel(VALUE obj)
{
    ZmqGetTimer(obj);
    timer->cancelled = TRUE;
    return Qnil; 
}
fire => Object click to toggle source
Fires a timer.

Examples

timer = ZMQ::Timer.new(1, 2){|arg| :fired }    =>  ZMQ::Timer
timer.fire(arg)
static VALUE rb_czmq_timer_fire(VALUE obj, VALUE args)
{
    ZmqGetTimer(obj);
    if (timer->cancelled == TRUE) rb_raise(rb_eZmqError, "cannot fire timer, already cancelled!");
    return rb_apply(timer->callback, intern_call, args); 
}
Also aliased as: call
on_error(exception) click to toggle source

Callback for error conditions such as exceptions raised in timer callbacks. Receives an exception instance as argument and raises by default.

handler.on_error(err) => raise

# File lib/zmq/timer.rb, line 8
def on_error(exception)
  raise exception
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.