Next style callback handler complete and working
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
import {Logger} from './logger';
|
||||
import {Config} from './config';
|
||||
import { resolve } from 'path';
|
||||
import { rejects } from 'assert';
|
||||
|
||||
export class Events { // extends rate limits
|
||||
async init(client) {
|
||||
this.client = client;
|
||||
this.client.login(Config.Token);
|
||||
// this.client.login(Config.Token);
|
||||
}
|
||||
|
||||
async handleEvents() {
|
||||
this.client.on('ready', async () => {
|
||||
this.handle(undefined,
|
||||
[this.handleReady, this.anotherCallback]
|
||||
[this.handleReady]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -22,20 +24,34 @@ export class Events { // extends rate limits
|
||||
}
|
||||
|
||||
async handle(obj = [null], callbacks = [undefined]) {
|
||||
// const next = undefined;
|
||||
// if (callbacks[i+1]) const next = callbacks[i+1];
|
||||
// callbacks[i](obj, next);
|
||||
let doNext = false;
|
||||
if (callbacks.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
async handleReady() {
|
||||
let next = function() {
|
||||
doNext = true;
|
||||
}
|
||||
|
||||
await callbacks[0](obj, next);
|
||||
callbacks.splice(0, 1);
|
||||
|
||||
if (doNext) {
|
||||
this.handle(obj, callbacks);
|
||||
}
|
||||
}
|
||||
|
||||
async handleReady(obj, next) {
|
||||
this.client.user.setPresence('online');
|
||||
this.client.user.setActivity(Config.NowPlaying);
|
||||
Logger.info(`Discord client logged in as ${this.client.user.tag}`);
|
||||
Logger.ready();
|
||||
}
|
||||
|
||||
async anotherCallback() {
|
||||
Logger.debug(1);
|
||||
await new Promise((resolve, reject) => {
|
||||
setTimeout(resolve, 1000);
|
||||
});
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
async handleMessage(...args) {
|
||||
|
||||
Reference in New Issue
Block a user