Sha256: f663a2b1d4c1ffb3c335fbad04b06575db1dea9635b77b07350105225ef07006

Contents?: true

Size: 883 Bytes

Versions: 15

Compression:

Stored size: 883 Bytes

Contents

# backtick_javascript: true

module Kernel
  def promise(p = Promise.new, &block)
    begin
      result = block.call
      return p.resolve(result) if result
      after(10) { promise(p, &block) }
    rescue => e
      return p.reject(e)
    end
    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
  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

15 entries across 15 versions & 1 rubygems

Version Path
isomorfeus-transport-23.9.0.rc12 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.9.0.rc11 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.9.0.rc10 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.9.0.rc9 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.9.0.rc8 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.9.0.rc7 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.9.0.rc6 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.9.0.rc5 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.9.0.rc4 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.9.0.rc3 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.9.0.rc2 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.9.0.rc1 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.8.0.rc3 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.8.0.rc2 lib/isomorfeus/core_ext/kernel.rb
isomorfeus-transport-23.8.0.rc1 lib/isomorfeus/core_ext/kernel.rb