Skip to content

Commit

Permalink
addon: Use a dedicated thread per client
Browse files Browse the repository at this point in the history
Removes the reuse of the uv threadpool in the old tdjson interface. This
also lifts the limitation of max UV_THREADPOOL_SIZE clients.

The timeout argument is moved from the receive binding to createClient.

bun seems to work after the removal of Napi::AsyncWorker, though the
stability might not be top notch. "Other JavaScript runtimes" section is
added to the README.
  • Loading branch information
eilvelia committed Oct 7, 2023
1 parent 1682bf1 commit aac78ca
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 289 deletions.
11 changes: 5 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
- `tdl.configure`: Added an experimental option `useNewTdjsonInterface` that
enables the use of `td_create_client_id`/`td_send`/`td_receive`/`td_execute`
interface with a client manager and global receive loop, though the old
interface still works well.
This does not use the libuv threadpool and does not have a limitation of max
`UV_THREADPOOL_SIZE` clients.
(TDLib v1.7.0+ only)
interface still works well. (TDLib v1.7.0+ only)
- Changed the implementation of the old tdjson interface bindings so that the
limitation of max `UV_THREADPOOL_SIZE` clients is lifted.
- `tdl.configure`: Added a `receiveTimeout` advanced option.
- `receiveTimeout` in the client options is deprecated.
- Deprecated the `useMutableRename` advanced option.
- `tdl.createClient`: `receiveTimeout` in the client options is deprecated.
- `tdl.createClient`: Deprecated the `useMutableRename` advanced option.

## tdl-install-types@0.1.0 (2023-09-26)

Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TDLib version 1.5.0 or newer is required.
- [Getting started](#getting-started)
- [API](#api)
- [Types](#types)
- [Creating multiple clients](#creating-multiple-clients)
- [Other JavaScript runtimes](#other-javascript-runtimes)
- [Possible errors](#possible-errors)

<a name="requirements"></a>
Expand Down Expand Up @@ -416,16 +416,17 @@ Note that when using `npx`, the version of `tdl-install-types` might be outdated
if you are not appending the `@latest` tag. You can also install the utility
globally or per-project as a dev dependency.

<a name="creating-multiple-clients"></a>
## Creating multiple clients
<a name="other-javascript-runtimes"></a>
## Other JavaScript runtimes

The current limitation is that the number of created clients should not exceed
[UV_THREADPOOL_SIZE][] (as for now, the default is 4, max is 1024).
Since [bun][] is Node.js-compatible and [supports Node-API][bun-napi], `tdl`
should work out of the box, however the stability may not be the best yet.

When `useNewTdjsonInterface` (experimental option) is set to true in
`tdl.configure`, this limitation does not apply.
[deno][] is not yet supported.

[UV_THREADPOOL_SIZE]: http://docs.libuv.org/en/v1.x/threadpool.html
[bun]: https://bun.sh/
[bun-napi]: https://github.com/oven-sh/bun/issues/158
[deno]: https://deno.com/

<a name="possible-errors"></a>
## Possible errors
Expand Down
2 changes: 0 additions & 2 deletions examples/multiple-accounts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// NOTE: The number of clients you create shouldn't be greater than UV_THREADPOOL_SIZE

const tdl = require('tdl')

const API_ID = 2222 // Your api_id
Expand Down
Loading

0 comments on commit aac78ca

Please sign in to comment.