Class: Asana::Resources::Events
- Inherits:
-
Object
- Object
- Asana::Resources::Events
- Includes:
- Enumerable
- Defined in:
- lib/asana/resource_includes/events.rb
Overview
An infinite collection of events.
Since they are infinite, if you want to filter or do other collection operations without blocking indefinitely you should call #lazy on them to turn them into a lazy collection.
Examples:
# Subscribes to an event stream and blocks indefinitely, printing
# information of every event as it comes in.
events = Events.new(resource: 'someresourceID', client: client)
events.each do |event|
puts [event.type, event.action]
end
# Lazily filters events as they come in and prints them.
events = Events.new(resource: 'someresourceID', client: client)
events.lazy.select { |e| e.type == 'task' }.each do |event|
puts [event.type, event.action]
end
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Iterates indefinitely over all events happening to a particular resource from the @sync timestamp or from now if it is nil.
-
#initialize(resource: required('resource'), client: required('client'), wait: 1, options: {}) ⇒ Events
constructor
Initializes a new Events instance, subscribed to a resource ID.
Constructor Details
#initialize(resource: required('resource'), client: required('client'), wait: 1, options: {}) ⇒ Events
Initializes a new Events instance, subscribed to a resource ID.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/asana/resource_includes/events.rb', line 35 def initialize(resource: required('resource'), client: required('client'), wait: 1, options: {}) @resource = resource @client = client @events = [] @wait = wait @options = @sync = nil @last_poll = nil end |
Instance Method Details
#each(&block) ⇒ Object
Iterates indefinitely over all events happening to a particular resource from the @sync timestamp or from now if it is nil.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/asana/resource_includes/events.rb', line 49 def each(&block) if block loop do poll if @events.empty? event = @events.shift yield event if event end else to_enum end end |