Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7547191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:23:26+00:00 2026-05-30T09:23:26+00:00

So, in javascript since it’s event-driven by its nature it seems that setTimeout doesn’t

  • 0

So, in javascript since it’s event-driven by its nature it seems that setTimeout doesn’t block. This means that if I do this:

setTimeout(function(){
  console.log('sleeping');
}, 10);
console.log('prints first!!');

It will output 'prints first!!' and then 'sleeping'.

The js interpreter won’t wait until setTimeout is done instead it executes the piece of code below it right away. When 10ms passes, then it executes the callback function.

Now I have been playing around with ruby recently. I know that it has non-blocking support in event-machine library. But I wonder if we can achieve something similar to setTimeout example I have just written in javascript with sleep or any function in ruby natively without event-machine support? Is this possible at all using closure proc or block or anything? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:23:27+00:00Added an answer on May 30, 2026 at 9:23 am

    The setTimeout function is nothing at all like sleep since the former is asynchronous and the latter is synchronous.

    The Ruby sleep method, like its POSIX counterpart, halts execution of the script. The setTimer function in JavaScript triggers a callback at a future time.

    If you want to trigger an asynchronous callback, you might need something like EventMachine to run an event loop for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

since i'm poor with javascript I would like someone to convert this small function
I am trying to rewrite a javascript function since I was told this function
Since Javascript doesn't have a built in set datatype has anyone come across a
Since JavaScript is not derived from Java, why does it have Java in the
Since Actionscript is a proper superset of javascript, it should I suppose be possible.
Javascript's getTime() method returns the number of milliseconds since midnight of January 1, 1970.
Since I installed IE8 (Win XP) Visual Studio 2008 Pro stopped deebugging javascript. When
Since I've started to use jQuery, I have been doing a lot more JavaScript
JavaScript does funky automatic conversions with objects: var o = {toString: function() {return 40;
Javascript I have code that will hide various sections in a MS CRM form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.