INDEX

Error-first callback

Spaceify has adopted the so called Error-first callback standard from Node.js. In this standard callbacks have error object as their first parameter and successful response data as second. This standard is followed throughout Spaceify's APIs.

  • If error occurs the error object is non-null and response data is null.
  • If error does not occur the error object is null and response data contains the successful data.

Spaceify extends the standard with two optional arguments: id and ms. Spaceify has also a standard error object. Below is the complete table of arguments returned by a JSON-RPC requests and applicable methods in the JavaScript API

Argument Type Description
err Object An error_object or null if no error occured.
data any The response from a successful method call. The type depends of the method that was called.
id DOMString Unique identifier used in the JSON-RPC request.
ms Number Round trip time of the JSON-RPC request in milliseconds.

Examples request and callback for response.

someService.callRpc("whoAreYou", [], this, myNameIs);

function myNameIs(err, data)
  {}
someService.callRpc("howFastAreYou", [], this, youTellMe);

function youTellMe(err, data, id, ms)
  {}
Close
copyright © Spaceify.org 2014