Class List Method List File List

# Class: Concurrent::Promises::Event

Inherits:
  AbstractEventFuture
  - Object
  - Synchronization::Object
  - AbstractEventFuture
  - Concurrent::Promises::Event
  show all
Defined in:
  lib/concurrent/edge/promises.rb

## Overview

Represents an event which will happen in future (will be resolved). The event is either pending or resolved. It should be always resolved. Use Future to communicate rejections and cancellation.

## Direct Known Subclasses

ResolvableEvent

## Constant Summary

## Instance Method Summary (collapse)

- - (Event) any(event_or_future) (also: #|)

  Creates a new event which will be resolved when the first of receiver, `event_or_future` resolves.

- - (Event) delay

  Creates new event dependent on receiver which will not evaluate until touched, see AbstractEventFuture#touch.

- - (Event) schedule(intended_time)

  Creates new event dependent on receiver scheduled to execute on/in intended_time.

- - (Event) to_event

  Returns self, since this is event.

- - (Future) to_future

  Converts event to a future.

- - (Event) with_default_executor(executor)

  Crates new object with same class with the executor set as its new default executor.

- - (Future, Event) zip(other) (also: #&)

  Creates a new event or a future which will be resolved when receiver and other are.

## Instance Method Details

### - (`Event`) any(event_or_future) Also known as: |

Creates a new event which will be resolved when the first of receiver, `event_or_future` resolves.

Returns:

- (`Event`)

    847
    848
    849

    # File 'lib/concurrent/edge/promises.rb', line 847

    def any(event_or_future)
      AnyResolvedEventPromise.new_blocked_by2(self, event_or_future, @DefaultExecutor).event
    end

### - (`Event`) delay

Creates new event dependent on receiver which will not evaluate until touched, see AbstractEventFuture#touch. In other words, it inserts delay into the chain of Futures making rest of it lazy evaluated.

Returns:

- (`Event`)

    857
    858
    859
    860

    # File 'lib/concurrent/edge/promises.rb', line 857

    def delay
      event = DelayPromise.new(@DefaultExecutor).event
      ZipEventEventPromise.new_blocked_by2(self, event, @DefaultExecutor).event
    end

### - (`Event`) schedule(intended_time)

Creates new event dependent on receiver scheduled to execute on/in intended_time. In time is interpreted from the moment the receiver is resolved, therefore it inserts delay into the chain.

Parameters:

- intended_time (`Numeric`, `Time`) —

  `Numeric` means to run in `intended_time` seconds. `Time` means to run on `intended_time`.

Returns:

- (`Event`)

    869
    870
    871
    872
    873
    874

    # File 'lib/concurrent/edge/promises.rb', line 869

    def schedule(intended_time)
      chain do
        event = ScheduledPromise.new(@DefaultExecutor, intended_time).event
        ZipEventEventPromise.new_blocked_by2(self, event, @DefaultExecutor).event
      end.flat_event
    end

### - (`Event`) to_event

Returns self, since this is event

Returns:

- (`Event`)

    887
    888
    889

    # File 'lib/concurrent/edge/promises.rb', line 887

    def to_event
      self
    end

### - (`Future`) to_future

Converts event to a future. The future is fulfilled when the event is resolved, the future may never fail.

Returns:

- (`Future`)

    879
    880
    881
    882
    883

    # File 'lib/concurrent/edge/promises.rb', line 879

    def to_future
      future = Promises.resolvable_future
    ensure
      chain_resolvable(future)
    end

### - (`Event`) with_default_executor(executor)

Crates new object with same class with the executor set as its new default executor. Any futures depending on it will use the new default executor.

Returns:

- (`Event`)

    893
    894
    895

    # File 'lib/concurrent/edge/promises.rb', line 893

    def with_default_executor(executor)
      EventWrapperPromise.new_blocked_by1(self, executor).event
    end

### - (`Future`, `Event`) zip(other) Also known as: &

Creates a new event or a future which will be resolved when receiver and other are. Returns an event if receiver and other are events, otherwise returns a future. If just one of the parties is Future then the result of the returned future is equal to the result of the supplied future. If both are futures then the result is as described in FactoryMethods#zip_futures_on.

Returns:

- (`Future`, `Event`)

    833
    834
    835
    836
    837
    838
    839

    # File 'lib/concurrent/edge/promises.rb', line 833

    def zip(other)
      if other.is_a?(Future)
        ZipFutureEventPromise.new_blocked_by2(other, self, @DefaultExecutor).future
      else
        ZipEventEventPromise.new_blocked_by2(self, other, @DefaultExecutor).event
      end
    end