opal/browser/delay.rb in opal-browser-0.2.0 vs opal/browser/delay.rb in opal-browser-0.3.0

- old
+ new

@@ -47,10 +47,21 @@ # # @return [Delay] the object representing the timeout def after!(time, &block) Delay.new(@native, time, &block) end + + # Returns a promise that will resolve after the given seconds. + # + # @param time [Float] the seconds after it gets called + # + # @return [Promise] the promise that will resolve after timeout happens + def resolve_after(time) + promise = Promise.new + Delay.new(@native, time) { promise.resolve }.start + promise + end end end module Kernel @@ -60,9 +71,14 @@ end # (see Browser::Window#after!) def after!(time, &block) $window.after!(time, &block) + end + + # (see Browser::Window#resolve_after) + def resolve_after(time) + $window.resolve_after(time) end end class Proc # (see Browser::Window#after)