Module: Geos::Interrupt
- Defined in:
- lib/ffi-geos/interrupt.rb
Instance Method Summary collapse
-
#available? ⇒ Boolean
Check for the availability of the GEOS interruption API.
-
#cancel ⇒ Object
Cancel a request to interrupt the current operation.
- #clear ⇒ Object
-
#register(method_or_block = nil, &block) ⇒ Object
Registers an interrupt method or block that may be called during certain operations such as Geos::Geometry#buffer.
-
#request ⇒ Object
Interrupt the current operation.
Instance Method Details
#available? ⇒ Boolean
Check for the availability of the GEOS interruption API. The interruption API was added in GEOS 3.4.0.
9 10 11 |
# File 'lib/ffi-geos/interrupt.rb', line 9 def available? true end |
#cancel ⇒ Object
Cancel a request to interrupt the current operation. This method should be called from within a callback registered with Geos::Interrupt.register but can be called at any time all the same.
55 56 57 |
# File 'lib/ffi-geos/interrupt.rb', line 55 def cancel FFIGeos.GEOS_interruptCancel end |
#clear ⇒ Object
59 60 61 62 |
# File 'lib/ffi-geos/interrupt.rb', line 59 def clear FFIGeos.GEOS_interruptRegisterCallback(nil) @current_interrupt_callback = nil end |
#register(method_or_block = nil, &block) ⇒ Object
Registers an interrupt method or block that may be called during certain operations such as Geos::Geometry#buffer. During these blocks you can interrupt the current operation using Geos::Interrupt.request and cancel that interrupt request using Geos::Interrupt.clear.
The return value for Geos::Interrupt.register is a reference to the previously registered callback, allowing you to chain interrupt calls together by calling #call on the previously registered callback.
HUGE NOTE CONCERNING INTERRUPTS: be careful when using interrupt blocks and how they reference other ruby objects. The ruby garbage collector may not play nicely with GEOS and objects may get cleaned up in unexpected ways while interrupts are firing.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ffi-geos/interrupt.rb', line 27 def register(method_or_block = nil, &block) raise ArgumentError, 'Expected either a method or a block for Geos::Interrupt.register' if method_or_block.nil? && !block_given? raise ArgumentError, 'Cannot use both a method and a block for Geos::Interrupt.register' if !method_or_block.nil? && block_given? retval = @current_interrupt_callback @current_interrupt_callback = if method_or_block FFIGeos.GEOS_interruptRegisterCallback(method_or_block) method_or_block elsif block_given? FFIGeos.GEOS_interruptRegisterCallback(block) block end retval end |
#request ⇒ Object
Interrupt the current operation. This method should generally be called from within a callback registered with Geos::Interrupt.register but can be called at any time to interrupt the next interruptable operation.
48 49 50 |
# File 'lib/ffi-geos/interrupt.rb', line 48 def request FFIGeos.GEOS_interruptRequest end |