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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:56:39+00:00 2026-06-03T15:56:39+00:00

I am trying to work out how to implement an asynchronous callback in node

  • 0

I am trying to work out how to implement an asynchronous callback in node given that I don’t know what the arguments could be.

I’ll state the sync version of what I’m trying to do so as to make this clearer.

function isAuthorized(userID){
    // check for user Permissions here
    return isAuthorized;
}

Using this any function can call it and, from the value it returns, determine if the user is authorized. However, the function that I use to get the userID (and check for permissions) are both asyncronous functions and require callbacks. However I have no idea how to get this implemented when I don’t know the arguments needed in the callback.

The function that calls this could want to send an number of arguments to the callback (normally it’d just wait for a return in sync) and that’s what’s confusing me.

function isAuthorized(socket, callback, args){
    socket.get('userID', function (err, userID) {
        //check userID for permission
        callback(args);
    });
}

I realize I could convert the arguments into an array and send that array, but I wanted to know if there is a more general way to do this that doesn’t force me to make all my callbacks convert from an array of arguments.

Hope you can help,
Pluckerpluck

  • 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-03T15:56:41+00:00Added an answer on June 3, 2026 at 3:56 pm

    You can always create a function to pull those arguments into an array for you, and then reuse it in each of your async functions:

    function asyncWithCallbackArgs(obj, callback) {
      var args = Array.prototype.slice.call(arguments, 2);
      callback.apply(obj, args);
    }
    

    This will then enable you to do things like this:

    function callback (c, d, e, f) {
      console.log([c, d, e, f]);
    }
    
    asyncWithCallbackArgs({}, callback,'c','d','e','f');​
    

    There’s a fiddle here to play with.

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

Sidebar

Related Questions

I'm trying to work out if there's a way that I could possibly implement
I've been trying to work out how to implement Church-encoded data types in Scala.
Trying to work out this whole web part personalisation, and trying to implement it
I'm trying to work out how to implement some machine learning library to help
I can't figure out a clean way to implement an algorithm that will work
I'm trying to figure out how to implement a function in a tree node
I am trying to work out how to implement a new piece of functionality
I am trying work out with MERGE statment to Insert / Update Dimension Table
Im trying to work out the best way to approach the following problem with
Im trying to work out how to get the value from one setting in

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.