Releases: QSmally/DispatchQueue
v0.6.0
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
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
v0.5.0
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
v0.4.2
v0.4.1
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
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 thanautomaticRejectionTime
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
v0.3.2
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
.