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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:24:40+00:00 2026-06-09T04:24:40+00:00

like many other peoples, I want to turn a async function of a third

  • 0

like many other peoples, I want to turn a async function of a third party module (Patio) into a sync function.

function get_user_message_list(parameters, array, response)
{
var new_array = [];
for (var i in array) {

    var json = array[i];
    json['content']['users_seen'] = ["1757842565"];
    json['content']['users_not_seen'] = [];

    new_array.push(json);
}

console.log("NEW ARRAY :");
console.log(new_array);

response.writeHeader(200, {'Content-Type':'application/json'});
response.end(JSON.stringify(new_array));
}

function get_json_message(parameters, json)
{
console.log("JSON OBJECT :");
console.log(json);
var dataset = db.from(TABLES.USER).join(TABLES.MOVIE_LIST, {MLUserId: sql.URId}).join(TABLES.MOVIE, {MVId: sql.MLMovieId});

dataset.where('MLSeen={seen} AND MVSourceId={movie} AND MVSource={source} AND URId!={user}', {seen: 1, movie: json['content']['movie_id'], source: json['content']['movie_source'], user:parameters.FACEBOOK_ID}).all().then(function(users){
    if (users) {
        for (var j in users) {
            json['content']['users_seen'].push(users[j].URId);
        }
    }

    //console.log(json['content']['users_seen']);

    dataset.where('MLSeen={seen} AND MVSourceId={movie} AND MVSource={source} AND URId!={user}', {seen: 0, movie: json['content']['movie_id'], source: json['content']['movie_source'], user:parameters.FACEBOOK_ID}).all().then(function(users){
        if (users) {
            for (var j in users) {
                json['content']['users_not_seen'].push(users[j].URId);
            }
        }

        console.log(json);
    }, errorHandler);
}, errorHandler);
}

In the get_user_message_list function I iterate into an array and for each iteration I calling the async function. In this async function I’m using Patio module to make request to MySQL database. But like you can see, I must wait for the query result to be get after sending a result to the previous function.

How can I wait for the query result to be got before I send it to the next function?

  • 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-06-09T04:24:41+00:00Added an answer on June 9, 2026 at 4:24 am

    You CAN and you SHOULD turn async functions into something that behaves like sync functions when a problem needs to be fixed. You can’t is never the correct answer, the shouldn’t is for the programmer to answer.

    So, I recently found some code in the nodeunit module which may help you. It fires the async functions, keep track of which are ready. After all requests are in, fires the callback. This could be the idea behind the solution to your problem (so no, this is not the final solution).

    async.forEachSeries = function (arr, iterator, callback) {
        if (!arr.length) {
            return callback();
        }
        var completed = 0;
        var iterate = function () {
            iterator(arr[completed], function (err) {
                if (err) {
                    callback(err);
                    callback = function () {};
                }
                else {
                    completed += 1;
                    if (completed === arr.length) {
                        callback();
                    }
                    else {
                        iterate();
                    }
                }
            });
        };
        iterate();
    };
    

    This test triggered me to see how it was done:

    exports['series'] = function (test) {
        var call_order = [];
        async.series([
            function (callback) {
                setTimeout(function () {
                    call_order.push(1);
                    callback(null, 1);
                }, 25);
            },
            function (callback) {
                setTimeout(function () {
                    call_order.push(2);
                    callback(null, 2);
                }, 50);
            },
            function (callback) {
                setTimeout(function () {
                    call_order.push(3);
                    callback(null, 3, 3);
                }, 15);
            }
        ],
        function (err, results) {
            test.equals(err, null);
            test.same(results, [1, 2, [3, 3]]);
            test.same(call_order, [1, 2, 3]);
            test.done();
        });
    };
    

    Happy programming!

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

Sidebar

Related Questions

Seen many other similar questions like this on this website and i would say
In c#, I would like the abstract class to be applied to many other
Like many other people posting questions here, I recently started programming in Python. I'm
Like many others Knockout developers before me, I encountered a slow running script warning
I, like many others, love Eclipse as my ide of choice, and because of
I am creating dynamic TextFields in actionscript 3.0. Like many others, my text disappears
This sounds like a problem many others have posted about, but there's a nuance
Like many people here, I started my programming experience with the good ol' green
Like many programmers, I'm prone to periodic fits of inspiration wherein I will suddenly
Like many people, I have several SVN repositories that contains several projects. I've decided

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.