Reputation: 631
I'm doing an async call to Redis and trying to use a callback to notify async.js the query has completed. I keep encountering an error stating "callback is not a function".
What am I doing wrong here?
"check": function (redisListItem, dataElement, callback) {
let lookupKey = redisListItem.table + dataElement;
let virtualField = redisListItem.virtualName;
client.get(lookupKey, function (err, reply) {
if (err) {
return callback(err)
}
else {
session.virtual[virtualField] = reply;
callback(session);
}
});
}
The call to "check" is being done as follows:
"condition": function(R) {
var self = this;
async.series([
function(R){
/////////THE CALL TO CHECK ////////
R.check(List.redisTables.List.negEmail, self.customer.email)
}.bind(this,R),
function(R) {
R.when(this.virtual.negEmail === "true")
}.bind(this,R)
])
}
Upvotes: 0
Views: 3116
Reputation: 318162
R.check(List.redisTables.List.negEmail, self.customer.email)
only has two arguments, the third argument, that should be a function, is missing, i.e. it's undefined
R.check(List.redisTables.List.negEmail, self.customer.email, function(session) {
// do something when "check()" has completed
})
As a sidenote, you should stick with Node conventions, and pass an error and data
client.get(lookupKey, function (err, reply) {
if (err) {
return callback(err, null)
} else {
session.virtual[virtualField] = reply;
callback(null, session);
}
});
that way you can actually check for errors
R.check(List.redisTables.List.negEmail, self.customer.email, function(err, session) {
if (err) throw new Error('fail')
// do something when "check()" has completed
})
Upvotes: 6