Sha256: fe15b018d7615b6e855159ed18f5fc95c9fdbb8d707f76867fd3173cf0bb63eb
Contents?: true
Size: 1.07 KB
Versions: 18
Compression:
Stored size: 1.07 KB
Contents
module Kernel def promise(&block) p = Promise.new begin result = block.call return p.resolve(result) if result rescue => e return p.reject(e) end pr = proc do begin res = block.call res ? p.resolve(res) : after(10, &pr) rescue => e p.reject(e) end end after(10, &pr) p end if RUBY_ENGINE == 'opal' def on_browser?; true; end def on_desktop?; false; end def on_mobile?; false; end def on_tablet?; false; end def on_tv?; false; end def on_server?; false; end def after(time_ms, &block) `setTimeout(#{block.to_n}, time_ms)` end # TODO remove before release %x{ Opal.s = function() { return Opal.Isomorfeus.store.$get_state().$to_n(); } } else def on_browser?; false; end def on_desktop?; false; end def on_mobile?; false; end def on_tablet?; false; end def on_tv?; false; end def on_server?; true; end def after(time_ms, &block) sleep time_ms/1000 block.call end end end
Version data entries
18 entries across 18 versions & 1 rubygems