# Any way to implement delay() with ruby code?

**URL:** <https://www.ruby-forum.com/t/any-way-to-implement-delay-with-ruby-code/93806>\
**Category:** Rails\
**Created:** [April 10, 2006, 11:56pm UTC](https://www.ruby-forum.com/t/any-way-to-implement-delay-with-ruby-code/93806 "2006-04-10T23:56:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [April 10, 2006, 11:56pm UTC](https://www.ruby-forum.com/t/any-way-to-implement-delay-with-ruby-code/93806/1 "2006-04-10T23:56:24Z")

</div>

That is, is there any way to do something like an RJS page.delay()  
except with  
ruby code statements in the body instead of RJS statements?

If not, what kind of options would I have for wanting to execute a set  
of statements n seconds in the future?

Thanks,  
Andy

---

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [April 11, 2006, 7:17am UTC](https://www.ruby-forum.com/t/any-way-to-implement-delay-with-ruby-code/93806/2 "2006-04-11T07:17:46Z")

</div>

What’s the purpose of the delay? I doubt you’d want the delay to occur  
in the processing of the rjs template as it would just delay the  
response of the whole action. If you are wanting a delay in client-side  
processing, I would suggest you look at the javascript setTimeout()  
method. You could simply have the rjs template call a client-side method  
that issues a setTimeout.

The setInterval() js method might also help you out depending on what  
you’re doing.

Cheers, Simon.

---

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [April 11, 2006, 9:29am UTC](https://www.ruby-forum.com/t/any-way-to-implement-delay-with-ruby-code/93806/3 "2006-04-11T09:29:10Z")

</div>

You could, start a new thread and let it sleep for some seconds and then  
execute, the code [http://www.rubycentral.com/book/tut\_threads.html](http://www.rubycentral.com/book/tut_threads.html)
