Slide 7
Slide 7 text
v2 Callbacks
function callbackHandler (callback, err) {
if (err && err.code !== as.status.AEROSPIKE_OK) {
callback(AerospikeError.fromASError(err))
} else {
var args = Array.prototype.slice.call(arguments, 2)
args.unshift(null)
callback.apply(undefined, args)
}
}
Client.prototype.get = function (key, policy, callback) {
if (typeof policy === 'function') {
callback = policy
policy = null
} else if (typeof callback !== 'function') {
throw new TypeError('"callback" must be a function')
}
this.as_client.getAsync(key, policy, function (err,
record, metadata) {
callbackHandler(callback, err, record, metadata, key)
})
}
client.get(key, function (err, record) {
if (err) throw err
// process record
})
• Error-first callbacks
following Node.js
conventions
• Null is passed in case
operation is successful