Class: Channel
- Inherits:
-
Object
- Object
- Channel
- Defined in:
- ext/channel/channel.c
Instance Method Summary collapse
- #<<(obj) ⇒ Object
- #deferrable? ⇒ Boolean
- #initialize(*args) ⇒ Object constructor
- #size ⇒ Object
- #subscribe(*args) ⇒ Object
- #subscribers ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'ext/channel/channel.c', line 63 static VALUE rb_channel_initialize( int argc, VALUE *argv, VALUE ch ) { VALUE size, defer; int channel_size, def; rb_scan_args(argc, argv, "02", &size, &defer); channel_size = NIL_P(size) ? 0 : FIX2INT(size); def = (defer == Qtrue) ? 1 : 0; return rb_channel_new(ch, channel_size, def); } |
Instance Method Details
#<<(obj) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'ext/channel/channel.c', line 128 static VALUE rb_channel_push( VALUE ch, VALUE obj ) { deferred_push_args args; RChannel* chs = GetChannelStruct(ch); if (chs->defer == 1){ args.chs = chs; args.obj = &obj; rb_thread_create(rb_channel_push1,&args); }else{ rb_channel_push0(chs,&obj); } return ch; } |
#deferrable? ⇒ Boolean
88 89 90 91 92 93 |
# File 'ext/channel/channel.c', line 88 static VALUE rb_channel_deferrable_p( VALUE ch ) { RChannel* chs = GetChannelStruct(ch); return (chs->defer == 1) ? Qtrue : Qfalse; } |
#size ⇒ Object
74 75 76 77 78 79 |
# File 'ext/channel/channel.c', line 74 static VALUE rb_channel_size( VALUE ch ) { RChannel* chs = GetChannelStruct(ch); return INT2FIX(chs->size); } |
#subscribe(*args) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'ext/channel/channel.c', line 95 static VALUE rb_channel_subscribe( int argc, VALUE *argv, VALUE ch ) { VALUE cb; RChannel* chs = GetChannelStruct(ch); if (!rb_block_given_p()) rb_raise(rb_eArgError, "Block callback required!"); if (chs->sbs == chs->size) rb_raise(rb_eArgError, "Maximum number of subscribers exceeded!"); cb = rb_block_proc(); chs->subscribers[chs->sbs] = cb; chs->sbs++; return ch; } |
#subscribers ⇒ Object
81 82 83 84 85 86 |
# File 'ext/channel/channel.c', line 81 static VALUE rb_channel_subscribers( VALUE ch ) { RChannel* chs = GetChannelStruct(ch); return INT2FIX(chs->sbs); } |