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

  • Home
  • SEARCH
  • 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 7502371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:50:46+00:00 2026-05-29T20:50:46+00:00

I wrote the following function to check if my HTML5 openDatabase table is filled

  • 0

I wrote the following function to check if my HTML5 openDatabase table is filled or empty:

var that = this;
that.db = openDatabase('dbname', '1.0', "description", 1024 * 1024);

that.tableFilled = function( tableName ) {

    that.db.transaction(function ( tx ) {

        tx.executeSql('SELECT * FROM ' + tableName, [],
            function success( c, results ) {
                return ( results.rows.length > 0 ? true : false );
            },
            function fail() {
                console.log('FAiL');
            }
        );

    });

};

I am trying to return the true or false values to tableFilled().

Actually that.tableFilled('tableName') returns undefined.

What I am trying to achieve at the end is:

if ( that.tableFilled('tableName') ){
    // ...
}

Is there a way I can return the true or false values to the parent function tableFilled() without using a callback ?

  • 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-29T20:50:48+00:00Added an answer on May 29, 2026 at 8:50 pm

    You’re dealing with an asynchronous process so you can’t return a value directly.

    What you can do however is return a promise. Your function will promise to give you that value when it’s available. To get the value out of the promise, you have to add a callback function.

    You still need to use a callback function but you don’t need to nest your functions anymore, you can just serialize them.

    This may be way out of scope for your current needs but it’s a very interesting concept. Just Google for it if you want to know more.

    Here is a short example:

    function my_function() {
        var promise = new_promise();
        do_asynchronous(function callback(result) {
            promise.resolve(result); // gets called after 1 second
        });
        return promise;
    }
    
    var promise = my_function();
    promise.done(function(result) {
        console.log(result);    // prints "yay!" after 1 second
    });
    
    function new_promise() {
        var handlers = [];
        return {
            "resolve": function (result) {
                for (var i = 0; i < handlers.length; i += 1) {
                    handlers[i](result);
                }
            },
            "done": function (a_callback) {
                handlers.push(a_callback);
            }
        };
    }
    
    function do_asynchronous(callback) {
        setTimeout(function () {
            callback("yay!");
        }, 1000);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a managed C++ class that has the following function: void EndPointsMappingWrapper::GetLastError(char* strErrorMessage)
I wrote the following: Object.prototype.length = function(){ var count = -1; for(var i in
All, I'm trying to write a function that would check in my users table
I just wrote the following C++ function to programmatically determine how much RAM a
I want to call the Sleep function on ASM. So I wrote the following:
Is it possible to write a C function that does the following? Allocate a
Check out the following snippet of HTML/Javascript code: <html> <head> <script type=text/javascript> var alerts
I have written following function which checks whether start_date field is not empty and
I wrote a small tcp client using boost::asio, providing the following function: typedef boost::function<void(const
So, my problem is the following: I have a mail client that I wrote

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.