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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:00:37+00:00 2026-05-30T06:00:37+00:00

I have the following function in coffeescript: newEdge: (fromVertexID, toVertexID) -> edgeID = this.NOID

  • 0

I have the following function in coffeescript:

newEdge: (fromVertexID, toVertexID) ->
    edgeID = this.NOID
    @client.methodCall('ubigraph.new_edge', [fromVertexID, toVertexID], (error, value) ->
        if(error)
            console.log('ubigraph.new_edge error: ' + error)
        edgeID = value
    )
    edgeID

where @client.methodCall refers to the xmlrpc library.
My question is how to return value as edgeID. Do I use a callback for that?

If so, should the callback look something like this: ?

# callback is passed the following parameters:
# 1. error - an error, if one occurs
# 2. edgeID - the value of the returned edge id
newEdge: (fromVertexID, toVertexID, callback) ->
    @client.methodCall('ubigraph.new_edge', [fromVertexID, toVertexID], (error, value) ->
        if(error)
            console.log('ubigraph.new_edge error: ' + error)
        edgeID = value
        callback(error, value)
    )
  • 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-30T06:00:39+00:00Added an answer on May 30, 2026 at 6:00 am

    Yes, callbacks are the usual solution for asynchronous calls, sometimes you have callbacks calling callbacks calling callbacks, callbacks all the way down. I’d probably do it a little differently though:

    newEdge: (fromVertexID, toVertexID, on_success = ->, on_error = ->) ->
        @client.methodCall('ubigraph.new_edge', [fromVertexID, toVertexID], (error, edge_id) ->
            if(error)
                console.log('ubigraph.new_edge error: ' + error)
                on_error(error)
            else
                on_success(edge_id)
        )
    

    The main difference is that mine has separate success and error callbacks so that the caller can handle these conditions separately, separate callbacks for different conditions is a common approach so it should be familiar to most people. I also added default no-op callbacks so that the callbacks are optional but the main method body can pretend that they’ve always been supplied.

    If you don’t like using four arguments then you could use “named” arguments for the callbacks:

    newEdge: (fromVertexID, toVertexID, callbacks = { }) ->
        @client.methodCall('ubigraph.new_edge', [fromVertexID, toVertexID], (error, edge_id) ->
            if(error)
                console.log('ubigraph.new_edge error: ' + error)
                callbacks.error?(error)
            else
                callbacks.success?(edge_id)
        )
    

    Using an object/hash for the callbacks lets you use the existential operator instead of no-ops to make the callbacks optional.


    Aaron Dufour notes that a single callback is the usual pattern in Node.js so your original approach would be a better fit for node.js:

    newEdge: (fromVertexID, toVertexID, callback = ->) ->
        @client.methodCall('ubigraph.new_edge', [fromVertexID, toVertexID], (error, edge_id) ->
            if(error)
                console.log('ubigraph.new_edge error: ' + error)
            callback(error, edge_id)
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Coffeescript: $ -> $('#new_event').submit -> $.post( $(this).attr('action') $(this).serialize() (data, textStatus,
i have following function in php, how can i convert this in javascript? function
I have following function. I want to call this function when user click on
I have following code function Model(onChanged) { this.array = new Array(); this.onChanged = onChanged;
Possible Duplicate: What does this mean? (function (x,y)){…}){a,b); in JavaScript I have the following
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
I have the following function that is pulling data from a database. The ajax
I have the following function: //Function to get random number public static int RandomNumber(int
I have the following function: - (NSString *)urlEncodedValue { NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(
I have the following function void initBoard(int * board[BOARD_ROWS][BOARD_COLS]){ int z = 0; for(

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.