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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:09:56+00:00 2026-05-27T13:09:56+00:00

I have an interesting situation that my usually clever mind hasn’t been able to

  • 0

I have an interesting situation that my usually clever mind hasn’t been able to come up with a solution for 🙂 Here’s the situation…

I have a class that has a get() method… this method is called to get stored user preferences… what it does is calls on some underlying provider to actually get the data… as written now, it’s calling on a provider that talks cookies… so, get() calls providerGet() let’s say, providerGet() returns a value and get() passes it along to the caller. The caller expects a response before it continues its work obviously.

Here’s the tricky part… I now am trying to implement a provider that is asychronous in nature (using local storage in this case)… so, providerGet() would return right away, having dispatched a call to local storage that will, some time later, call a callback function that was passed to it… but, since providerGet() already returned, and so did get() now by extension to the original called, it obviously hasn’t returned the actual retrieved data.

So, the question is simply is there a way to essentially “block” the return from providerGet() until the asychronous call returns? Note that for my purposes I’m not concerned with the performance implications this might have, I’m just trying to figure out how to make it work.

I don’t think there’s a way, certainly I know I haven’t been able to come up with it… so I wanted to toss it out and see what other people can come up with 🙂

edit: I’m just learning now that the core of the problem, the fact that the web sql API is asychronous, may have a solution… turns out there’s a synchronous version of the API as well, something I didn’t realize… I’m reading through docs now to see how to use it, but that would solve the problem nicely since the only reason providerGet() was written asychronously at all was to allow for that provider… the code that get() is a part of is my own abstraction layer above various storage providers (cookies, web sql, localStorage, etc) so the lowest common denominator has to win, which means if one is asychronous they ALL have to be asychronous… the only one that was is web sql… so if there’s a way to do that synchronously my point become moot (still an interesting question generically I think though)

edit2: Ah well, no help there it seems… seems like the synchronous version of the API isn’t implemented in any browser and even if it was it’s specified that it can only be used from worker threads, so this doesn’t seem like it’d help anyway. Although, reading some other things it sounds like there’s a way to pull of this trick using recursion… I’m throwing together some test code now, I’ll post it if/when I get it working, seems like a very interesting way to get around any such situation generically.

edit3: As per my comments below, there’s really no way to do exactly what I wanted. The solution I’m going with to solve my immediate problem is to simply not allow usage of web SQL for data storage. It’s not the ideal solution, but as that spec is in flux and not widely implemented anyway it’s not the end of the world… hopefully when its properly supported the synchronous version will be available and I can plug in a new provider for it and be good to go. Generically though, there doesn’t appear to be any way to pull of this miracle… confirms what I expected was the case, but wish I was wrong this one time 🙂

  • 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-27T13:09:57+00:00Added an answer on May 27, 2026 at 1:09 pm

    No, you can’t block until the asynch call finishes. It’s that simple.

    It sounds like you may already know this, but if you want to use asynchronous ajax calls, then you have to restructure the way your code is used. You cannot just have a .get() method that makes an asynchronous ajax call, blocks until it’s complete and returns the result. The design pattern most commonly used in these cases (look at all of Google’s javascript APIs that do networking, for example) is to have the caller pass you a completion function. The call to .get() will start the asynchronous operation and then return immediately. When the operation completes, the completion function will be called. The caller must structure their code accordingly.

    You simply cannot write straight, sequential procedural javascript code when using asynchronous networking like:

    var result = abc.get()
    document.write(result);
    

    The most common design pattern is like this:

    abc.get(function(result) {
        document.write(result);
    });
    

    If your problem is several calling layers deep, then callbacks can be passed along to different levels and invoked when needed.


    FYI, newer browsers support the concept of promises which can then be used with async and await to write code that might look like this:

    async function someFunc() {
        let result = await abc.get()
        document.write(result);
    }
    

    This is still asynchronous. It is still non-blocking. abc.get() must return a promise that resolves to the value result. This code must be inside a function that is declared async and other code outside this function will continue to run (that’s what makes this non-blocking). But, you get to write code that “looks” more like blocking code when local to the specific function it’s contained within.

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

Sidebar

Related Questions

I have an interesting situation that EMF forced me into: abstract class AbstractDog{ ...
I have an interesting SQL problem that I need help with. Here is the
I have an interesting situation, well it's probably not that unique at all, but
We've run into an interesting situation that needs solving, and my searches have turned
I have an interesting situation here this time. This more of a conceptual question,
I have an interesting situation that has me stumped. It seems that posting appliction/json
I have this interesting situation. I have a bunch of structs that hold a
I have an interesting situation here. I am building a board game and I
Hi folks hi have a very interesting situation. i have a viewmodel that requires
I have an interesting problem to solve here that may require some creative direction.

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.