Skip to content

Commit

Permalink
chore: refactor telegram client
Browse files Browse the repository at this point in the history
  • Loading branch information
zdm committed Nov 23, 2024
1 parent 335a262 commit 1d59bbc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/api/telegram/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export default class TelegramClientApi {

constructor ( { apiId, apiHash, session, deviceModel, appVersion, connectionRetries = Infinity, logLevel, connect, ...options } = {} ) {
this.#startManager = new StartManager( {
"onStart": this.#connect.bind( this ),
"onStop": this.#disconnect.bind( this ),
"doStart": this.#connect.bind( this ),
"doStop": this.#disconnect.bind( this ),
} );

const stringSession = new StringSession( session );
Expand Down
38 changes: 19 additions & 19 deletions lib/threads/start-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export default class StartManager {
#stopMutex = new Mutex();
#activeRequestsCounter = new Counter();
#abortController = new AbortController();
#onStart;
#onStop;
#doStart;
#doStop;

constructor ( { onStart, onStop } = {} ) {
this.onStart = onStart;
this.onStop = onStop;
constructor ( { doStart, doStop } = {} ) {
this.doStart = doStart;
this.doStop = doStop;
}

// properties
Expand All @@ -37,20 +37,20 @@ export default class StartManager {
return this.#abortController.signal;
}

get onStart () {
return this.#onStart;
get doStart () {
return this.#doStart;
}

set onStart ( callback ) {
this.#onStart = callback;
set doStart ( callback ) {
this.#doStart = callback;
}

get onStop () {
return this.#onStop;
get doStop () {
return this.#doStop;
}

set onStop ( callback ) {
this.#onStop = callback;
set doStop ( callback ) {
this.#doStop = callback;
}

// public
Expand All @@ -69,7 +69,7 @@ export default class StartManager {
var res;

try {
res = result.try( await this._onStart( options ), {
res = result.try( await this._doStart( options ), {
"allowUndefined": true,
} );
}
Expand Down Expand Up @@ -109,7 +109,7 @@ export default class StartManager {
var res;

try {
res = result.try( await this._onStop( options ), {
res = result.try( await this._doStop( options ), {
"allowUndefined": true,
} );
}
Expand Down Expand Up @@ -144,11 +144,11 @@ export default class StartManager {
}

// protected
async _onStart ( options ) {
return this.#onStart?.( options );
async _doStart ( options ) {
return this.#doStart?.( options );
}

async _onStop ( options ) {
return this.#onStop?.( options );
async _doStop ( options ) {
return this.#doStop?.( options );
}
}

0 comments on commit 1d59bbc

Please sign in to comment.