mtproto-core icon indicating copy to clipboard operation
mtproto-core copied to clipboard

.close() or .stop() method

Open SARFEX opened this issue 5 years ago • 8 comments

How can I stop background processing? process.exit() is not a solution :)

SARFEX avatar May 15 '20 18:05 SARFEX

What do you mean by "background processing"?

alik0211 avatar May 16 '20 06:05 alik0211

I need to execute a single command, and then complete the process. But it does not close and waits, probably because of socket connection.

SARFEX avatar May 16 '20 07:05 SARFEX

Why process.exit() is not a solution?

alik0211 avatar May 20 '20 09:05 alik0211

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).

SergeyFromHell avatar Aug 02 '20 17:08 SergeyFromHell

Interesting. I may add a stop in future versions.

alik0211 avatar Aug 06 '20 16:08 alik0211

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

Elexy avatar Apr 10 '21 10:04 Elexy

I plan to add a stop method

alik0211 avatar Apr 11 '21 10:04 alik0211

Any update from 2021?)

andreieuganox avatar Mar 07 '24 10:03 andreieuganox