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 5953333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:48:38+00:00 2026-05-22T17:48:38+00:00

Sorry about the title but could not come up with anything really informative and

  • 0

Sorry about the title but could not come up with anything really informative and concise.

My situation is that I am launching a setTimeout and I want it to be able to run in the middle of a JS function (it is used to get around the issue with injecting GM functions into the web page).

unsafeWindow.testG = function(key, dValue){
var rValue;
setTimeout(function(){rValue = GM_getValue(key, dValue);}, 0);
alert(rValue);
alert(rValue);
return(rValue);
}

In the three tests rValue is still undefined (which makes sense because JS is single threaded for the most part).

So I have 2 solutions I have thought of.

Favourite:
Is there anyway to tell JS to sleep in the middle of a function and work on background stuff (like Timeouts)?

Other:
Does anyone know when this timeout will be called? Maybe after this function execution but before whatever called it starts up again?
In that case making rValue global would solve the issue (but make slightly messier coding).

Or will it wait until all JS is done executing?
In that case I would possibly need another setTimeout to process the result.

  • 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-22T17:48:39+00:00Added an answer on May 22, 2026 at 5:48 pm

    There is no way what you’re asking for can be accompished. Until HTML5 is a wide spread standard, you can’t do what you’re asking without thinking asynchronously.

    For example :

    unsafeWindow.testG = function(key, dValue, callback){
       var rValue;
       setTimeout(function(){
          rValue = GM_getValue(key, dValue);
          callback(rValue);
       }, 0);
    }
    

    and call this with a callback :

    unsafewindow.testG(key, dValue, function(rValue) {
       alert(rValue);
    });
    alert("foo");
    

    For the last sippet, "foo" will be echoed before rValue, because testG will execute the timeout function only when the Javascript thread is available, or only when there’s no other script running.

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

Sidebar

Related Questions

First, I'm sorry about the title, that was the best I could come up
Sorry for bad title. I could not come up with anything better. Every example
First of all, sorry about that title. I'm not the best at writing those
It's a badly worded title but I can't come up with anything better, sorry!
Sorry about the title, couldn't really think of anything else to describe the problem
Sorry about the title but I can't really think of a quick way of
Sorry if title is not too clear but I think it's about right. NEhow,
I really didnt know what to put to the title so sorry about that.
Sorry about the vague title, but I really don't know how to describe this
Sorry for the atrocious title, but I could not think of a better way

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.