Create a utility function to wrap those on-the-fly callbacks

This commit is contained in:
meew0
2015-12-31 19:08:28 +01:00
parent a0995c6fe7
commit f50c910af3

View File

@@ -14,6 +14,16 @@ function constructErrorCallback(callback) {
}; };
} }
// This utility function creates an anonymous handler function to separate the
// error and the data arguments inside a callback and return the data if it is
// eventually done (for promise propagation).
function dataCallback(callback) {
return data => {
callback(null, data);
return data;
}
}
export default class Client extends EventEmitter { export default class Client extends EventEmitter {
/* /*
this class is an interface for the internal this class is an interface for the internal
@@ -253,25 +263,25 @@ export default class Client extends EventEmitter {
//def banMember //def banMember
banMember(user, server, length = 1, callback = (/*err*/) => { }) { banMember(user, server, length = 1, callback = (/*err*/) => { }) {
if (typeof length === "function") { if (typeof length === "function") {
// length is the callback // length is the callback
callback = length; callback = length;
} }
return this.internal.banMember(user, server, length) return this.internal.banMember(user, server, length)
.then(callback, constructErrorCallback(callback)); .then(() => {}, constructErrorCallback(callback));
} }
//def unbanMember //def unbanMember
unbanMember(user, server, callback = (/*err*/) => { }) { unbanMember(user, server, callback = (/*err*/) => { }) {
return this.internal.unbanMember(user, server) return this.internal.unbanMember(user, server)
.then(callback, constructErrorCallback(callback)); .then(() => {}, constructErrorCallback(callback));
} }
//def kickMember //def kickMember
kickMember(user, server, callback = (/*err*/) => { }) { kickMember(user, server, callback = (/*err*/) => { }) {
return this.internal.kickMember(user, server) return this.internal.kickMember(user, server)
.then(callback, constructErrorCallback(callback)); .then(() => {}, constructErrorCallback(callback));
} }
//def createRole //def createRole