Non-blocking Timed event in Ruby like JavaScript setTimeout -


i need change property on class few minutes after it initialized. attempted use sleep inside function delayed execution of everything:

active = true  def deactivate   sleep 120   puts 'deactivate'   active = false end  deactivate puts active 

what hoping happen true log out first 2 minutes later deactivate log. however, happens deactivate false log out after 2 minutes.

in javascript like:

var active = true; settimeout(function(){   console.log('deactivate');   active = false; },120000); console.log(active); 

looks overkill task, can use delayed_job run task @ future time asynchronously.

  def deactivate      puts 'deactivate'      active = false   end    active = true   handle_asynchronously :deactivate, :run_at => proc.new { 2.minutes.from_now } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -