Skip to content

Releases: QSmally/DispatchQueue

v0.6.0

23 Sep 14:20
Compare
Choose a tag to compare

This release drafts a new version of DispatchQueue.

DispatchQueue Parameters

For the other feature in this release, I had to rework how parameters are provided in the DispatchQueue initialiser. For threadAmount, lazyInitialisation and dataContext, an options object needs to be constructed. The path argument is still the first, required parameter of the constructor.

const dispatch = new DispatchQueue("path/to/worker.js", {
    threadAmount: 3,            // still defaults to `os.cpus().length`.
    lazyInitialisation: true,   // still defaults to `false`.
    dataContext: { foo: "bar" } // defaults to an empty object.
});

DataContext

DispatchThread can now accept a dataContext object from the origin thread. Internally, this is the workerData passed to the thread.

class Thread extends DispatchQueue.Thread {
    onPayload(data) {
        // this.dataContext -> { foo: "bar" }
    }
}
  • this.dataContext -> Object - returns the worker data that was inputted when creating the queue.

v0.5.2

22 Sep 15:22
Compare
Choose a tag to compare

This release drafts a patch version of DispatchQueue.

Fixes

  • Fixes and clarifications in documentation.

Improvements

  • Refactor the internal Task structure;
  • Patch redundancy in ThreadController in terms of the asynchronous block;
  • Rename DispatchQueue's thread defer property to lazyInitialisation.

v0.5.1

14 Sep 18:07
Compare
Choose a tag to compare

This release drafts a patch version of DispatchQueue.

Fixes

  • Fixes in documentation.

Improvements

  • Internal Task class, instead of an untyped object;
  • Clarifications in README.

v0.5.0

11 Sep 09:45
Compare
Choose a tag to compare

This release drafts a new version of DispatchQueue.

Fixes

  • Fixes in property documentations.

Grand Central Dispatch

Taking on the title of GCD fully, DispatchQueue now implements one primary queue, in contrast to the queues being distributed across the number of worker threads before. Nothing in terms of the API was changed.

I mostly figured that this transformation was necessary because of the following reason. As each ThreadInstance had its queue, it would stall whenever the worker thread crashed because of the overhead produced by spawning another thread. Internally, the library needed a rework of its queue and how tasks would lock the promise generated from that queue.

v0.4.3

02 Sep 19:25
Compare
Choose a tag to compare

This release drafts a patch version of DispatchQueue.

Fixes

  • Fix properties in documentation;
  • Patch inconsistencies in access models.

v0.4.2

25 Aug 13:49
Compare
Choose a tag to compare

This release drafts a patch version of DispatchQueue.

Improvements

  • Consistent usage of properties in structs;
  • Internal symbol name changes, such as isStillInitialising and deferInitialisation.

v0.4.1

16 Aug 09:06
Compare
Choose a tag to compare

This release drafts a patch version of DispatchQueue.

Fixes

  • Fix documentations.

Improvements

  • Add engines field in package descriptor (Node >=14);
  • Internal refactors to calculate ideal thread and changes in DispatchGroup;
  • Default onSpawn method in DispatchThread logs "Thread x spawned."

v0.4.0

13 Aug 12:09
Compare
Choose a tag to compare

This release drafts a new version of DispatchQueue.

Fixes

  • Patch thread not restarting when the queue isn't empty but is scheduled for exit.

AutomaticRejectionTime

DispatchThread implements a new behavioural property, automaticRejectionTime. If a task couldn't be completed in x milliseconds, the onTimeExceeded method will be executed (which is by default throwing an error, but if you need to, you can execute clean-up tasks).

const DispatchQueue = require("dispatchqueue");

class Thread extends DispatchQueue.Thread {
    // terminate the execution process if the task
    // takes 30 milliseconds or longer to be marked
    // as complete.
    static automaticRejectionTime = 30;

    onPayload(data) {
        // ...
    }

    // optional
    onTimeExceeded() {
        // ...
        throw new Error("Took too long");
    }
}

new Thread();
  • abstract onTimeExceeded() - runs whenever the task takes longer than automaticRejectionTime in ms.

Important note

The feature is only tested when throwing an error, and using a default resolve call will result in undefined behaviour. The normal task execution cycle can still continue processing after resolve was called, and that's the reason why onTimeExceeded will crash the thread instead. You are expected to do the same.

v0.3.3

12 Aug 15:56
Compare
Choose a tag to compare

This release drafts a patch version of DispatchQueue.

Fixes

  • Fix tests.

Improvements

  • Lazy imports for both DispatchGroup and DispatchThread;
  • Modified termination log with remaining queue amount.

v0.3.2

06 Aug 08:17
Compare
Choose a tag to compare

This release drafts a patch version of DispatchQueue.

DispatchThread Identifier

The property <DispatchThread>.id has been renamed to <DispatchThread>.identifier. In usage, you'd use this.identifier instead of the previous property key.

For the ThreadInstance class, this property still is <DispatchThread>.threadId.