From 274a05dc9eff0e2d93cf98544dba27934b6c0dc5 Mon Sep 17 00:00:00 2001 From: teidesu <86301490+teidesu@users.noreply.github.com> Date: Sat, 26 Jun 2021 23:51:48 +0300 Subject: [PATCH] fix(node): made .run sync forgot the entire idea of .run, lol. i should get some sleep ig --- packages/node/index.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/node/index.ts b/packages/node/index.ts index 75886b52..c4ab6821 100644 --- a/packages/node/index.ts +++ b/packages/node/index.ts @@ -89,10 +89,10 @@ export class NodeTelegramClient extends TelegramClient { return new Promise((res) => this._rl!.question(text, res)) } - async run( + run( params: Parameters[0], then?: (user: User) => void | Promise - ): Promise { + ): void { if (!params.botToken) { if (!params.phone) params.phone = () => this.input('Phone > ') if (!params.code) params.code = () => this.input('Code > ') @@ -100,12 +100,14 @@ export class NodeTelegramClient extends TelegramClient { params.password = () => this.input('2FA password > ') } - await super.run(params, then) + super.run(params, (user) => { + if (this._rl) { + this._rl.close() + delete this._rl + } - if (this._rl) { - this._rl.close() - delete this._rl - } + return then?.(user) + }) } close(): Promise {