module Geos::Interrupt

Public Class Methods

available?() click to toggle source

Check for the availability of the GEOS interruption API. The interruption API was added in GEOS 3.4.0.

# File lib/ffi-geos/interrupt.rb, line 9
def available?
  true
end
cancel() click to toggle source

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.

# File lib/ffi-geos/interrupt.rb, line 55
def cancel
  FFIGeos.GEOS_interruptCancel
end
clear() click to toggle source
# 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) click to toggle source

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.

# 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() click to toggle source

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.

# File lib/ffi-geos/interrupt.rb, line 48
def request
  FFIGeos.GEOS_interruptRequest
end