JavaScript has the asynchronous nature, and CroJSDoc provides some tags for documentation asynchronicity.

NodeJS style's callback

Use @nodejscallback.

// (Borrowed from Node.js Manual)

/**
 * Asynchronously reads the entire contents of a file.
 * @param {String} filename
 * @param {Object} [options]
 * @param {String} [options.encoding=null]
 * @param {String} [options.flag='r']
 * @return {String}
 * @nodejscallback
 */
function readFile(filename, options, callback) {
  require('fs').readFile(filename, options, callback);
}

readFile('test', { encoding: 'utf-8' }, function (error, content) {
  console.log(content);
});
# (Borrowed from Node.js Manual)

##
# Asynchronously reads the entire contents of a file.
# @param {String} filename
# @param {Object} [options]
# @param {String} [options.encoding=null]
# @param {String} [options.flag='r']
# @return {String}
# @nodejscallback
readFile = (filename, options, callback) ->
  require('fs').readFile filename, options, callback

readFile 'test', encoding: 'utf-8', (error, content) ->
  console.log content

The result of the above comment:

Asynchronously reads the entire contents of a file.

Parameters

NameTypeDescription
filenameString
optionsoptionalObject
encoding=nulloptionalString
flag='r'optionalString
callbackFunction(error, result) NodeJS style's callback
errorError See throws
resultString See returns

Returns asNodeJS callback

NameTypeDescription
(Returns)String

Promise

Use @promise.

/**
 * Asynchronously reads the entire contents of a file.
 * @param {String} filename
 * @param {Object} [options]
 * @param {String} [options.encoding=null]
 * @param {String} [options.flag='r']
 * @return {String}
 * @promise
 */
function readFile(filename, options) {
  return Promise.promisify(require('fs').readFile)(filename, options);
}

readFile('test', { encoding: 'utf-8' })
.then(function (content) {
  console.log(content);
});
##
# Asynchronously reads the entire contents of a file.
# @param {String} filename
# @param {Object} [options]
# @param {String} [options.encoding=null]
# @param {String} [options.flag='r']
# @return {String}
# @promise
readFile = (filename, options) ->
  Promise.promisify(require('fs').readFile) filename, options

readFile 'test', encoding: 'utf-8'
.then (content) ->
  console.log content

The result of the above comment:

Asynchronously reads the entire contents of a file.

Parameters

NameTypeDescription
filenameString
optionsoptionalObject
encoding=nulloptionalString
flag='r'optionalString

Returns asPromise

NameTypeDescription
(Returns)String

Together

@nodejscallback and @promise can be used together.

/**
 * Asynchronously reads the entire contents of a file.
 * @param {String} filename
 * @param {Object} [options]
 * @param {String} [options.encoding=null]
 * @param {String} [options.flag='r']
 * @return {String}
 * @nodejscallback
 * @promise
 */
function readFile(filename, options, callback) {
  return Promise.promisify(require('fs').readFile)(filename, options)
  .nodeify(callback);
}

readFile('test', { encoding: 'utf-8' }, function (error, content) {
  console.log(content);
});
// or
readFile('test', { encoding: 'utf-8' })
.then(function (content) {
  console.log(content);
});
##
# Asynchronously reads the entire contents of a file.
# @param {String} filename
# @param {Object} [options]
# @param {String} [options.encoding=null]
# @param {String} [options.flag='r']
# @return {String}
# @nodejscallback
# @promise
readFile = (filename, options, callback) ->
  Promise.promisify(require('fs').readFile) filename, options
  .nodeify callback

readFile 'test', encoding: 'utf-8', (error, content) ->
  console.log content
# or
readFile 'test', encoding: 'utf-8'
.then (content) ->
  console.log content

The result of the above comment:

Asynchronously reads the entire contents of a file.

Parameters

NameTypeDescription
filenameString
optionsoptionalObject
encoding=nulloptionalString
flag='r'optionalString
callbackoptionalFunction(error, result) NodeJS style's callback
errorError See throws
resultString See returns

Returns asPromiseNodeJS callback

NameTypeDescription
(Returns)String

Use ordinary tags

If you don't use NodeJS style's callback or the function returns an other value immediately, you can use ordinary tags.

// (Borrowed from CORMO)

/**
 * Finds a record by id.
 *
 * If a callback is given, it returns the record in the callback.
 * Otherwise, it returns an Query object for chaining.
 * @param {RecordID} id
 * @param {Function} [callback]
 * @param {Error} callback.error
 * @param {Model} callback.record
 * @return {Query}
 */
find = function (id, callback) {}
# (Borrowed from CORMO)

##
# Finds a record by id.
#
# If a callback is given, it returns the record in the callback.
# Otherwise, it returns an Query object for chaining.
# @param {RecordID} id
# @param {Function} [callback]
# @param {Error} callback.error
# @param {Model} callback.record
# @return {Query}
@find: (id, callback) ->

The result of the above comment:

Finds a record by id.

If a callback is given, it returns the record in the callback. Otherwise, it returns an Query object for chaining.

Parameters

NameTypeDescription
idRecordID
callbackoptionalFunction(error, record)
errorError
recordModel

Returns

NameTypeDescription
(Returns)Query
Fork me on GitHub