dashpay / dashd-rpc

Dash Client Library to connect to Dash Core (dashd) via RPC
MIT License
16 stars 65 forks source link

DH 7: ref: nix async lib in the simplest way #61

Closed coolaj86 closed 5 months ago

coolaj86 commented 1 year ago

This is built on other PRs now, so the relevant commit is just 7fea699806705831b38b384289694df0a7f62c63.

This replaces async with Promise in the simplest way possible.

Much of the time task pools are used with such a high number that they actually cause thrashing and decrease performance.

My assumption that the magic number of 16 tasks probably wasn't tested, but just chosen at random and this would actually be more performant queuing single tasks in a row anyway.

Since it's being called on a batch (which already contains some number of requests), I think that even more.

Built on #60 just look at https://github.com/dashpay/dashd-rpc/commit/b94b29127ec88daf9345bbf42877c4d6f4845285 for actual code changes.

Essentially:

- this.queue = async.queue((task, callback) => {
-   task(callback);
- }, queueSize);
+ this._chain = Promise.resolve();
+ this.queue = {
+   push: function (task) {
+     const taskAsync = promisify(task);
+     this._chain = this._chain.then(async function () {
+       await taskAsync();
+     });
+   },
+ };