Module: ZeevexDelayed

Defined in:
lib/zeevex_delayed.rb,
lib/zeevex_delayed/promise.rb,
lib/zeevex_delayed/version.rb,
lib/zeevex_delayed/thread_promise.rb

Defined Under Namespace

Classes: Promise, ThreadPromise

Constant Summary collapse

VERSION =
"0.9.2"

Class Method Summary collapse

Class Method Details

.Promise(*args, &block) ⇒ Object



4
5
6
# File 'lib/zeevex_delayed/promise.rb', line 4

def self.Promise(*args, &block)
  ZeevexDelayed::Promise.new(*args, &block)
end

.promise(*args, &block) ⇒ Object



8
9
10
# File 'lib/zeevex_delayed/promise.rb', line 8

def self.promise(*args, &block)
  ZeevexDelayed::Promise.new(*args, &block)
end

.thread_promise(*args, &block) ⇒ Object



23
24
25
# File 'lib/zeevex_delayed/thread_promise.rb', line 23

def self.thread_promise(*args, &block)
  ZeevexDelayed::ThreadPromise.new(*args, &block)
end

.ThreadPromise(*args, &block) ⇒ Object

Like a Promise, but evaluate and cache values on a per-thread basis

e.g. will act just like a Promise if only called from one thread, but if Thread A and Thread B both access a Promise created like so:

promise { Thread.current.object_id }

Then they will see different values. This does cache, and it does not GC its cache when threads exit. Thus if you expect to have a very long-lived Promise accessed from many different threads that come and go, don’t use this.



19
20
21
# File 'lib/zeevex_delayed/thread_promise.rb', line 19

def self.ThreadPromise(*args, &block)
  ZeevexDelayed::ThreadPromise.new(*args, &block)
end