A base class for sdk with some common & useful functions.
-
.ready(flagOrFunction)
flagOrFunction is optional, and the argument type can be Boolean, Error or Function.
client.ready(true);
client.ready(new Error('init failed'));
client.ready(err => {
if (err) {
console.log('client init failed');
console.error(err);
return;
}
console.log('client is ready');
});
client.ready()
.then(() => { ... })
.catch(err => { ... });
yield client.ready();
-
.on(event, listener)
wrap the EventEmitter.prototype.on(event, listener), the only difference is to support adding generator listener on events, except 'error' event.
-
once(event, listener)
wrap the EventEmitter.prototype.once(event, listener), the only difference is to support adding generator listener on events, except 'error' event.
-
prependListener(event, listener)
wrap the EventEmitter.prototype.prependListener(event, listener), the only difference is to support adding generator listener on events, except 'error' event.
-
prependOnceListener(event, listener)
wrap the EventEmitter.prototype.prependOnceListener(event, listener), the only difference is to support adding generator listener on events, except 'error' event.
-
addListener(event, listener)
wrap the EventEmitter.prototype.addListener(event, listener), the only difference is to support adding generator listener on events, except 'error' event.
client.on('data', function* (data) {
});
client.once('foo', function* (bar) {
});
client.on('error', function(err) {
console.error(err.stack);
});
-
.await(event)
: await an event, return a promise, and it will resolve(reject if event is error
) once this event emmited.
co(function* () {
const data = yield client.await('data');
});