mtproto-core
mtproto-core copied to clipboard
.close() or .stop() method
How can I stop background processing? process.exit() is not a solution :)
What do you mean by "background processing"?
I need to execute a single command, and then complete the process. But it does not close and waits, probably because of socket connection.
Why process.exit() is not a solution?
I use a trick:
function close() {
// to protect myself from using closed instance of MTProto:
mt.call = () => {
throw new Error('MTProto has been closed.');
};
// shutdown all connections and forbid to connect:
for (let rpc of Object.values(mt.rpcs)) {
rpc.transport.connect = () => {};
rpc.transport.socket.destroy();
};
}
But it surely would be better to have a proper api function for that purpose. Closing the whole process is not an option - it could do many other things, only one of which is telegram operations. And there could be unknown in forward (dynamic) set of accounts to operate (my case).
Interesting. I may add a stop in future versions.
I use the library to test a bot so I can use @SergeyFromHell 's trick with a process.exit() at the end. Would be nice to have a proper stop().
Even nicer would be a method like run_until_complete() as in Telethon
I plan to add a stop method
Any update from 2021?)