Module: Extensions::DatabaseEvent::ActiveRecord::Base

Defined in:
lib/extensions/database_event/active_record/base.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#signalObject

Signals to possible waiting consumers on this record.


87
88
89
# File 'lib/extensions/database_event/active_record/base.rb', line 87

def signal
  self.class.signal(notify_identifier)
end

#wait(timeout: nil, while_callback: nil, &block) ⇒ Boolean, ...

Waits for a signal on the current record. A signal can be sent by using #signal.

Parameters:

  • timeout (Integer|nil)

    The timeout to wait for a message. A +nil+ or zero timeout will wait indefinitely.

  • while_callback (Proc)

    The callback that will be called after the +LISTEN+ statement is sent, and is used to check to see if the library should continue waiting for a notification event. If this returns +false+, the named of the last received notification is returned. If no notification was received yet (i.e. before the first wait), this returns false.

Returns:

  • (Boolean)

    If a +while+ callback was specified and it returned false before the first wait, this returns false.

  • (String)

    Otherwise, this returns the notification received.

  • (nil)

    If the notification received is +nil+.


82
83
84
# File 'lib/extensions/database_event/active_record/base.rb', line 82

def wait(timeout: nil, while_callback: nil, &block)
  self.class.wait(notify_identifier, timeout: timeout, while_callback: while_callback, &block)
end