Class: UringMachine::AsyncOp
- Inherits:
-
Object
- Object
- UringMachine::AsyncOp
- Defined in:
- ext/um/um_async_op_class.c,
ext/um/um_async_op_class.c
Overview
Encapsulates an asynchronous operation. Currently the only asynchronous operation supported is a timeout operation.
Instance Method Summary collapse
-
#await ⇒ Integer
Waits for the operation to complete.
-
#cancel ⇒ UringMachine::AsyncOp
Cancels the operation.
-
#cancelled? ⇒ bool
Returns true if the operation has been cancelled.
-
#done? ⇒ bool
Returns true if the operation has completed.
- #initialize ⇒ Object constructor
-
#join ⇒ Integer
Waits for the operation to complete.
-
#kind ⇒ Symbol
Returns the kind of asynchronous operation.
-
#result ⇒ Integer?
Returns the operation result.
Constructor Details
#initialize ⇒ Object
48 49 50 51 52 |
# File 'ext/um/um_async_op_class.c', line 48 VALUE AsyncOp_initialize(VALUE self) { struct um_async_op *async_op = AsyncOp_data(self); memset(async_op, 0, sizeof(struct um_async_op)); return self; } |
Instance Method Details
#await ⇒ Integer
Waits for the operation to complete.
124 125 126 127 128 129 130 131 132 |
# File 'ext/um/um_async_op_class.c', line 124 VALUE AsyncOp_await(VALUE self) { struct um_async_op *async_op = AsyncOp_data(self); raise_on_missing_op(async_op); if (async_op_is_done(async_op)) return INT2NUM(async_op->op->result.res); return um_async_op_await(async_op); } |
#cancel ⇒ UringMachine::AsyncOp
Cancels the operation.
138 139 140 141 142 143 144 145 146 |
# File 'ext/um/um_async_op_class.c', line 138 VALUE AsyncOp_cancel(VALUE self) { struct um_async_op *async_op = AsyncOp_data(self); raise_on_missing_op(async_op); if (!async_op_is_done(async_op)) um_async_op_cancel(async_op); return self; } |
#cancelled? ⇒ bool
Returns true if the operation has been cancelled.
111 112 113 114 115 116 117 118 |
# File 'ext/um/um_async_op_class.c', line 111 VALUE AsyncOp_cancelled_p(VALUE self) { struct um_async_op *async_op = AsyncOp_data(self); raise_on_missing_op(async_op); if (!async_op_is_done(async_op)) return Qnil; return (async_op->op->result.res == -ECANCELED) ? Qtrue : Qfalse; } |
#done? ⇒ bool
Returns true if the operation has completed.
89 90 91 92 93 94 |
# File 'ext/um/um_async_op_class.c', line 89 VALUE AsyncOp_done_p(VALUE self) { struct um_async_op *async_op = AsyncOp_data(self); raise_on_missing_op(async_op); return async_op_is_done(async_op) ? Qtrue : Qfalse; } |
#join ⇒ Integer
Waits for the operation to complete.
124 125 126 127 128 129 130 131 132 |
# File 'ext/um/um_async_op_class.c', line 124 VALUE AsyncOp_await(VALUE self) { struct um_async_op *async_op = AsyncOp_data(self); raise_on_missing_op(async_op); if (async_op_is_done(async_op)) return INT2NUM(async_op->op->result.res); return um_async_op_await(async_op); } |
#kind ⇒ Symbol
Returns the kind of asynchronous operation.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'ext/um/um_async_op_class.c', line 73 VALUE AsyncOp_kind(VALUE self) { struct um_async_op *async_op = AsyncOp_data(self); raise_on_missing_op(async_op); switch(async_op->op->kind) { case OP_TIMEOUT: return SYM_timeout; default: um_raise_internal_error("Invalid op kind"); } } |
#result ⇒ Integer?
Returns the operation result. If the operation is not completed, returns nil.
100 101 102 103 104 105 |
# File 'ext/um/um_async_op_class.c', line 100 VALUE AsyncOp_result(VALUE self) { struct um_async_op *async_op = AsyncOp_data(self); raise_on_missing_op(async_op); return async_op_is_done(async_op) ? INT2NUM(async_op->op->result.res) : Qnil; } |