Class: Elevate::ElevateOperation

Inherits:
NSOperation
  • Object
show all
Defined in:
lib/elevate/operation.rb

Overview

Executes an Elevate task, firing callbacks along the way.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exceptionException? (readonly)

Returns the exception that terminated this task, if any.

If the task has not finished, returns nil.

Returns:

  • (Exception, nil)

    exception that terminated the task



63
64
65
# File 'lib/elevate/operation.rb', line 63

def exception
  @exception
end

#resultObject? (readonly)

Returns the result of the task block.

If the task has not finished, returns nil.

Returns:

  • (Object, nil)

    result of the task block



73
74
75
# File 'lib/elevate/operation.rb', line 73

def result
  @result
end

Instance Method Details

#cancelvoid

This method returns an undefined value.

Cancels the currently running task.



27
28
29
30
31
# File 'lib/elevate/operation.rb', line 27

def cancel
  @coordinator.cancel

  super
end

#initWithTarget(target, args: args, channel: channel) ⇒ ElevateOperation

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Designated initializer.

Returns:



11
12
13
14
15
16
17
18
19
20
# File 'lib/elevate/operation.rb', line 11

def initWithTarget(target, args: args, channel: channel)
  if init
    @coordinator = IOCoordinator.new
    @context = TaskContext.new(target, channel, args)
    @exception = nil
    @result = nil
  end

  self
end

#mainvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Runs the specified task.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/elevate/operation.rb', line 38

def main
  @coordinator.install

  begin
    unless @coordinator.cancelled?
      @result = @context.execute
    end

  rescue => e
    @exception = e
  end

  @coordinator.uninstall

  @context = nil
end

#timeoutvoid

This method returns an undefined value.

Cancels any waiting operation with a TimeoutError, interrupting execution. This is not the same as #cancel.



81
82
83
# File 'lib/elevate/operation.rb', line 81

def timeout
  @coordinator.cancel(TimeoutError)
end