@hoast/base-process v3.1.0
@hoast/base-process
Provides basic functionality for process package like an initialization function, sequentially running of certain code, and filtering out running the process based of the data. Meant for developers to be used as a base for a hoast process package.
Install
npm install @hoast/base-processUsage
Extends BasePackage.
Constructor
constructorCreate package instance.@param {Object} ...OptionsOptions objects which can contain the following keys.{Function} filter = nullCustom filter function. The item data is given as the parameter. Returntrueif it should be processed, returnfalseif this processor should be skipped.{Number} logLevel = 2Log level given to the logger.
Functions
async nextWill be called by hoast itself to process the given item.@param {Any} dataData to process.@returns {Any}Item to be processed.
Abstract functions
The following functions can be implemented by the derived class and will automatically called if present. All functions are optional and don't have to be asynchronous.
async initializeCalled only once before sequential and concurrent.async sequentialCalled sequentially for each iteration call. Meaning while this method is running it won't be called until the ongoing call is finished.@params {Any}Item.@returns {Any}Item.
async concurrentCalled concurrently for each iteration call after the sequential call. Meaning this will run after the sequential call and in contrast to the sequential function will be called before a previous call has finished.@params {Any}Item.@returns {Any}Item.
async finalCalled after the processor has iterated over all data.
Example
// Import base modules.
import BaseProcess from '@hoast/base-process'
class NewProcess extends BaseProcess {
constructor(options) {
super({
// Default options.
}, options)
}
async initialize() {
// Initialize.
}
async sequential(data) {
// Sequential.
return data
}
async concurrent(data) {
// Concurrent.
return data
}
async final() {
// Final.
}
}
export default NewProcessSee the @hoast/process-writefiles package for another example.