- 
      
- 
        Save justinrolston/6974426 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | module EventuallyHelper | |
| def eventually(options = {}) | |
| timeout = options[:timeout] || 10 | |
| interval = options[:interval] || 0.1 | |
| time_limit = Time.now + timeout | |
| loop do | |
| begin | |
| yield | |
| rescue => error | |
| end | |
| return if error.nil? | |
| raise error if Time.now >= time_limit | |
| sleep interval | |
| end | |
| end | |
| end | |
| # usage: | |
| # it "should return a result of 5" do | |
| # eventually { long_running_thing.result.should eq(5) } | |
| # end | |
| module AsyncHelper | |
| def eventually(options = {}) | |
| timeout = options[:timeout] || 2 | |
| interval = options[:interval] || 0.1 | |
| time_limit = Time.now + timeout | |
| loop do | |
| begin | |
| yield | |
| rescue => error | |
| end | |
| return if error.nil? | |
| raise error if Time.now >= time_limit | |
| sleep interval | |
| end | |
| end | |
| end | |
| # Can we put this into RSpec somewhere? | 
        
      
            dorianmariecom
  
      
      
      commented 
        Nov 18, 2021 
      
    
  
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment