@rapidrest/core 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.rst +37 -0
- package/dist/lib/AlertUtils.js +239 -0
- package/dist/lib/AlertUtils.js.map +1 -0
- package/dist/lib/ApiError.js +34 -0
- package/dist/lib/ApiError.js.map +1 -0
- package/dist/lib/ClassLoader.js +159 -0
- package/dist/lib/ClassLoader.js.map +1 -0
- package/dist/lib/FileUtils.js +190 -0
- package/dist/lib/FileUtils.js.map +1 -0
- package/dist/lib/JWTUtils.js +111 -0
- package/dist/lib/JWTUtils.js.map +1 -0
- package/dist/lib/Logger.js +28 -0
- package/dist/lib/Logger.js.map +1 -0
- package/dist/lib/MessagingUtils.js +218 -0
- package/dist/lib/MessagingUtils.js.map +1 -0
- package/dist/lib/NotificationsUtils.js +52 -0
- package/dist/lib/NotificationsUtils.js.map +1 -0
- package/dist/lib/OASUtils.js +207 -0
- package/dist/lib/OASUtils.js.map +1 -0
- package/dist/lib/ObjectFactory.js +302 -0
- package/dist/lib/ObjectFactory.js.map +1 -0
- package/dist/lib/ObjectUtils.js +49 -0
- package/dist/lib/ObjectUtils.js.map +1 -0
- package/dist/lib/StringUtils.js +104 -0
- package/dist/lib/StringUtils.js.map +1 -0
- package/dist/lib/TelemetryUtils.js +159 -0
- package/dist/lib/TelemetryUtils.js.map +1 -0
- package/dist/lib/UserUtils.js +138 -0
- package/dist/lib/UserUtils.js.map +1 -0
- package/dist/lib/ValidationUtils.js +130 -0
- package/dist/lib/ValidationUtils.js.map +1 -0
- package/dist/lib/decorators/ObjectDecorators.js +95 -0
- package/dist/lib/decorators/ObjectDecorators.js.map +1 -0
- package/dist/lib/decorators/index.js +2 -0
- package/dist/lib/decorators/index.js.map +1 -0
- package/dist/lib/index.js +18 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/sleep.js +15 -0
- package/dist/lib/sleep.js.map +1 -0
- package/dist/lib/threads/ThreadLogger.js +43 -0
- package/dist/lib/threads/ThreadLogger.js.map +1 -0
- package/dist/lib/threads/ThreadPool.js +270 -0
- package/dist/lib/threads/ThreadPool.js.map +1 -0
- package/dist/lib/threads/ThreadWorker.js +25 -0
- package/dist/lib/threads/ThreadWorker.js.map +1 -0
- package/dist/lib/threads/ThreadWorkerEntry.js +77 -0
- package/dist/lib/threads/ThreadWorkerEntry.js.map +1 -0
- package/dist/lib/threads/index.js +3 -0
- package/dist/lib/threads/index.js.map +1 -0
- package/dist/types/AlertUtils.d.ts +132 -0
- package/dist/types/ApiError.d.ts +13 -0
- package/dist/types/ClassLoader.d.ts +87 -0
- package/dist/types/FileUtils.d.ts +46 -0
- package/dist/types/JWTUtils.d.ts +139 -0
- package/dist/types/Logger.d.ts +7 -0
- package/dist/types/MessagingUtils.d.ts +77 -0
- package/dist/types/NotificationsUtils.d.ts +32 -0
- package/dist/types/OASUtils.d.ts +54 -0
- package/dist/types/ObjectFactory.d.ts +77 -0
- package/dist/types/ObjectUtils.d.ts +17 -0
- package/dist/types/StringUtils.d.ts +52 -0
- package/dist/types/TelemetryUtils.d.ts +84 -0
- package/dist/types/UserUtils.d.ts +61 -0
- package/dist/types/ValidationUtils.d.ts +66 -0
- package/dist/types/decorators/ObjectDecorators.d.ts +55 -0
- package/dist/types/decorators/index.d.ts +1 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/sleep.d.ts +5 -0
- package/dist/types/threads/ThreadLogger.d.ts +15 -0
- package/dist/types/threads/ThreadPool.d.ts +115 -0
- package/dist/types/threads/ThreadWorker.d.ts +41 -0
- package/dist/types/threads/ThreadWorkerEntry.d.ts +1 -0
- package/dist/types/threads/index.d.ts +2 -0
- package/docs/Makefile +20 -0
- package/docs/conf.py +58 -0
- package/docs/index.rst +17 -0
- package/docs/make.bat +35 -0
- package/docs/reference/@rapidrest/namespaces/ObjectDecorators/README.md +21 -0
- package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Config.md +47 -0
- package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Destroy.md +27 -0
- package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Init.md +33 -0
- package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Inject.md +45 -0
- package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Logger.md +27 -0
- package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Nullable.md +27 -0
- package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Validator.md +39 -0
- package/docs/reference/@rapidrest/namespaces/ObjectDecorators/type-aliases/ValidatorFunction.md +31 -0
- package/docs/reference/README.md +73 -0
- package/docs/reference/classes/AlertUtils.md +158 -0
- package/docs/reference/classes/ApiError.md +263 -0
- package/docs/reference/classes/ClassLoader.md +224 -0
- package/docs/reference/classes/Event.md +109 -0
- package/docs/reference/classes/EventUtils.md +123 -0
- package/docs/reference/classes/FileUtils.md +193 -0
- package/docs/reference/classes/JWTUtils.md +91 -0
- package/docs/reference/classes/MessagingUtils.md +145 -0
- package/docs/reference/classes/OASUtils.md +213 -0
- package/docs/reference/classes/ObjectFactory.md +274 -0
- package/docs/reference/classes/ObjectUtils.md +60 -0
- package/docs/reference/classes/StringUtils.md +169 -0
- package/docs/reference/classes/ThreadPool.md +249 -0
- package/docs/reference/classes/ThreadWorker.md +91 -0
- package/docs/reference/classes/UserUtils.md +239 -0
- package/docs/reference/classes/ValidationUtils.md +294 -0
- package/docs/reference/enumerations/AlertPriority.md +61 -0
- package/docs/reference/enumerations/JWTUtilsCompressionMethods.md +21 -0
- package/docs/reference/enumerations/WorkerMessageType.md +43 -0
- package/docs/reference/functions/sleep.md +25 -0
- package/docs/reference/interfaces/Alert.md +101 -0
- package/docs/reference/interfaces/AlertAttachment.md +51 -0
- package/docs/reference/interfaces/AlertClose.md +31 -0
- package/docs/reference/interfaces/AlertUtilsAttachmentOptions.md +42 -0
- package/docs/reference/interfaces/AlertUtilsOptions.md +41 -0
- package/docs/reference/interfaces/InstanceOptions.md +35 -0
- package/docs/reference/interfaces/JWTPayload.md +143 -0
- package/docs/reference/interfaces/JWTUser.md +55 -0
- package/docs/reference/interfaces/JWTUtilsConfig.md +45 -0
- package/docs/reference/interfaces/JWTUtilsPayloadKeyOptions.md +68 -0
- package/docs/reference/interfaces/JWTUtilsPayloadOptions.md +40 -0
- package/docs/reference/interfaces/JWTUtilsPayloadPasswordOptions.md +78 -0
- package/docs/reference/interfaces/NewEvent.md +25 -0
- package/docs/reference/interfaces/OriginSettings.md +25 -0
- package/docs/reference/interfaces/SlackConfig.md +33 -0
- package/docs/reference/interfaces/SmtpAuth.md +25 -0
- package/docs/reference/interfaces/SmtpConfig.md +41 -0
- package/docs/reference/interfaces/Template.md +81 -0
- package/docs/reference/interfaces/TemplateMapBase.md +13 -0
- package/docs/reference/interfaces/TwilioConfig.md +33 -0
- package/docs/reference/interfaces/WorkerMessage.md +31 -0
- package/docs/reference/interfaces/WorkerOptions.md +61 -0
- package/docs/reference/type-aliases/BooleanFunc.md +23 -0
- package/docs/reference/type-aliases/TemplateMap.md +17 -0
- package/docs/reference/type-aliases/WorkerCallback.md +31 -0
- package/docs/reference/variables/Logger.md +21 -0
- package/package.json +96 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
[**@rapidrest/core**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@rapidrest/core](../README.md) / StringUtils
|
|
6
|
+
|
|
7
|
+
# Class: StringUtils
|
|
8
|
+
|
|
9
|
+
Defined in: src/StringUtils.ts:10
|
|
10
|
+
|
|
11
|
+
Utility functions for working with strings.
|
|
12
|
+
|
|
13
|
+
## Author
|
|
14
|
+
|
|
15
|
+
Jean-Philippe Steinmetz
|
|
16
|
+
|
|
17
|
+
## Constructors
|
|
18
|
+
|
|
19
|
+
### Constructor
|
|
20
|
+
|
|
21
|
+
> **new StringUtils**(): `StringUtils`
|
|
22
|
+
|
|
23
|
+
#### Returns
|
|
24
|
+
|
|
25
|
+
`StringUtils`
|
|
26
|
+
|
|
27
|
+
## Methods
|
|
28
|
+
|
|
29
|
+
### findAndReplace()
|
|
30
|
+
|
|
31
|
+
> `static` **findAndReplace**(`contents`, `variables`): `string`
|
|
32
|
+
|
|
33
|
+
Defined in: src/StringUtils.ts:46
|
|
34
|
+
|
|
35
|
+
Performs a search and replace on the provided contents with the map of variable replacements. The contents
|
|
36
|
+
must use Mustache formatted tokens such as `{{toreplace}}`.
|
|
37
|
+
|
|
38
|
+
#### Parameters
|
|
39
|
+
|
|
40
|
+
##### contents
|
|
41
|
+
|
|
42
|
+
`string`
|
|
43
|
+
|
|
44
|
+
The stringt to perform the find and replace on.
|
|
45
|
+
|
|
46
|
+
##### variables
|
|
47
|
+
|
|
48
|
+
`any`
|
|
49
|
+
|
|
50
|
+
A map of key=>value pairs to search for and replace.
|
|
51
|
+
|
|
52
|
+
#### Returns
|
|
53
|
+
|
|
54
|
+
`string`
|
|
55
|
+
|
|
56
|
+
***
|
|
57
|
+
|
|
58
|
+
### getParameters()
|
|
59
|
+
|
|
60
|
+
> `static` **getParameters**(`str`): `string`[]
|
|
61
|
+
|
|
62
|
+
Defined in: src/StringUtils.ts:18
|
|
63
|
+
|
|
64
|
+
Returns a list of all parameters contained within the string. A parameter is a bracket delimited substring
|
|
65
|
+
(e.g. /my/{key}/with/{id}).
|
|
66
|
+
|
|
67
|
+
#### Parameters
|
|
68
|
+
|
|
69
|
+
##### str
|
|
70
|
+
|
|
71
|
+
`string`
|
|
72
|
+
|
|
73
|
+
The string to search for parameters.
|
|
74
|
+
|
|
75
|
+
#### Returns
|
|
76
|
+
|
|
77
|
+
`string`[]
|
|
78
|
+
|
|
79
|
+
A list of parameters contained in the provided string.
|
|
80
|
+
|
|
81
|
+
***
|
|
82
|
+
|
|
83
|
+
### replaceAll()
|
|
84
|
+
|
|
85
|
+
> `static` **replaceAll**(`str`, `match`, `prefix`): `string`
|
|
86
|
+
|
|
87
|
+
Defined in: src/StringUtils.ts:82
|
|
88
|
+
|
|
89
|
+
Replaces all instances of the match regex pattern with the contents of the inner regular expression pattern for
|
|
90
|
+
the given string.
|
|
91
|
+
|
|
92
|
+
e.g.
|
|
93
|
+
|
|
94
|
+
let result = replaceAll('/my/path/{id}', new RegExp('\{([^\}]+)\}'), ':');
|
|
95
|
+
console.log(result); // -> /my/path/:id
|
|
96
|
+
|
|
97
|
+
#### Parameters
|
|
98
|
+
|
|
99
|
+
##### str
|
|
100
|
+
|
|
101
|
+
`string`
|
|
102
|
+
|
|
103
|
+
The string to perform replacement on.
|
|
104
|
+
|
|
105
|
+
##### match
|
|
106
|
+
|
|
107
|
+
The regular expression pattern to match containing an outer and inner pattern.
|
|
108
|
+
|
|
109
|
+
`string` | `RegExp`
|
|
110
|
+
|
|
111
|
+
##### prefix
|
|
112
|
+
|
|
113
|
+
`string`
|
|
114
|
+
|
|
115
|
+
The prefix to prepend the replacement text with.
|
|
116
|
+
|
|
117
|
+
#### Returns
|
|
118
|
+
|
|
119
|
+
`string`
|
|
120
|
+
|
|
121
|
+
The fully replaced contents of the string.
|
|
122
|
+
|
|
123
|
+
***
|
|
124
|
+
|
|
125
|
+
### toCamelCase()
|
|
126
|
+
|
|
127
|
+
> `static` **toCamelCase**(`str`): `string`
|
|
128
|
+
|
|
129
|
+
Defined in: src/StringUtils.ts:100
|
|
130
|
+
|
|
131
|
+
Converts the first character in the given string to be lowercase (e.g. myVariable).
|
|
132
|
+
|
|
133
|
+
#### Parameters
|
|
134
|
+
|
|
135
|
+
##### str
|
|
136
|
+
|
|
137
|
+
`string`
|
|
138
|
+
|
|
139
|
+
The string to convert to camelCase.
|
|
140
|
+
|
|
141
|
+
#### Returns
|
|
142
|
+
|
|
143
|
+
`string`
|
|
144
|
+
|
|
145
|
+
The string converted to camelCase.
|
|
146
|
+
|
|
147
|
+
***
|
|
148
|
+
|
|
149
|
+
### toPascalCase()
|
|
150
|
+
|
|
151
|
+
> `static` **toPascalCase**(`str`): `string`
|
|
152
|
+
|
|
153
|
+
Defined in: src/StringUtils.ts:110
|
|
154
|
+
|
|
155
|
+
Converts the first character in the given string to be uppercase (e.g. MyVariable).
|
|
156
|
+
|
|
157
|
+
#### Parameters
|
|
158
|
+
|
|
159
|
+
##### str
|
|
160
|
+
|
|
161
|
+
`string`
|
|
162
|
+
|
|
163
|
+
The string to convert to PascalCase.
|
|
164
|
+
|
|
165
|
+
#### Returns
|
|
166
|
+
|
|
167
|
+
`string`
|
|
168
|
+
|
|
169
|
+
The string converted to PascalCase.
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
[**@rapidrest/core**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@rapidrest/core](../README.md) / ThreadPool
|
|
6
|
+
|
|
7
|
+
# Class: ThreadPool
|
|
8
|
+
|
|
9
|
+
Defined in: src/threads/ThreadPool.ts:62
|
|
10
|
+
|
|
11
|
+
The `ThreadPool` class provides an interface for managing a pool of execution threads that can be used for parallel
|
|
12
|
+
code execution. `ThreadPool` is a wrapper to the `worker_threads` API to add support for multiple `Worker` instances.
|
|
13
|
+
By default, the pool will create *n* workers corresponding to the number of CPUs (physical + virtual) on the system.
|
|
14
|
+
|
|
15
|
+
There are two ways to start worker threads with the pool.
|
|
16
|
+
|
|
17
|
+
The first way is to set the `entry` option when calling the `start()` function. This will create a instance of the
|
|
18
|
+
`worker_threads` APIs `Worker` class with the specified file as the entry point. Note that this file must be of
|
|
19
|
+
type JavaScript (`.js` extension) as the underlying system does not support loading TypeScript. If the `args` option
|
|
20
|
+
is set, the value will be passed in as the `workerData` to the entry file.
|
|
21
|
+
|
|
22
|
+
The second way to start a worker thread is by setting the `worker` argument when calling the `start()` function. The
|
|
23
|
+
specified `worker` file must contain a `default` export. The `default` export must be a class definition which
|
|
24
|
+
extends the `ThreadWorker` abstract class interface. The file can be either JavaScript or TypeScript. When using
|
|
25
|
+
this method the `start()` function will return only when all worker instances in each thread of the pool has
|
|
26
|
+
successfully returned from its `start()` function. When the `args` option is set, the value(s) will be passed in to
|
|
27
|
+
the constructor on instantiation by the thread executor.
|
|
28
|
+
|
|
29
|
+
When the `restartOnExit` option is specified, the pool will automatically recreate and start a worker thread on
|
|
30
|
+
the `exit event`.
|
|
31
|
+
|
|
32
|
+
This class exposes worker messages via the `on()` callback handler function. Registering a callback handler via
|
|
33
|
+
`on()` will propogate all messages from all underlying threads in the pool.
|
|
34
|
+
|
|
35
|
+
## Author
|
|
36
|
+
|
|
37
|
+
Jean-Philippe Steinmetz
|
|
38
|
+
|
|
39
|
+
## Constructors
|
|
40
|
+
|
|
41
|
+
### Constructor
|
|
42
|
+
|
|
43
|
+
> **new ThreadPool**(`max`, `logger?`): `ThreadPool`
|
|
44
|
+
|
|
45
|
+
Defined in: src/threads/ThreadPool.ts:98
|
|
46
|
+
|
|
47
|
+
Creates a new `ThreadPool` instance with the specified defaults.
|
|
48
|
+
|
|
49
|
+
#### Parameters
|
|
50
|
+
|
|
51
|
+
##### max
|
|
52
|
+
|
|
53
|
+
`number` = `0`
|
|
54
|
+
|
|
55
|
+
The maximum number of threads to create. Default is `os.cpus().length`.
|
|
56
|
+
|
|
57
|
+
##### logger?
|
|
58
|
+
|
|
59
|
+
`any`
|
|
60
|
+
|
|
61
|
+
The Winston logger instance to forward all worker thread logs to.
|
|
62
|
+
|
|
63
|
+
#### Returns
|
|
64
|
+
|
|
65
|
+
`ThreadPool`
|
|
66
|
+
|
|
67
|
+
## Properties
|
|
68
|
+
|
|
69
|
+
### workers
|
|
70
|
+
|
|
71
|
+
> `readonly` **workers**: `Worker`[]
|
|
72
|
+
|
|
73
|
+
Defined in: src/threads/ThreadPool.ts:74
|
|
74
|
+
|
|
75
|
+
The list of active worker threads.
|
|
76
|
+
|
|
77
|
+
## Accessors
|
|
78
|
+
|
|
79
|
+
### max
|
|
80
|
+
|
|
81
|
+
#### Get Signature
|
|
82
|
+
|
|
83
|
+
> **get** **max**(): `number`
|
|
84
|
+
|
|
85
|
+
Defined in: src/threads/ThreadPool.ts:81
|
|
86
|
+
|
|
87
|
+
The maximum number of threads that can be created by the pool.
|
|
88
|
+
|
|
89
|
+
##### Returns
|
|
90
|
+
|
|
91
|
+
`number`
|
|
92
|
+
|
|
93
|
+
***
|
|
94
|
+
|
|
95
|
+
### size
|
|
96
|
+
|
|
97
|
+
#### Get Signature
|
|
98
|
+
|
|
99
|
+
> **get** **size**(): `number`
|
|
100
|
+
|
|
101
|
+
Defined in: src/threads/ThreadPool.ts:88
|
|
102
|
+
|
|
103
|
+
The number of active threads in the pool.
|
|
104
|
+
|
|
105
|
+
##### Returns
|
|
106
|
+
|
|
107
|
+
`number`
|
|
108
|
+
|
|
109
|
+
## Methods
|
|
110
|
+
|
|
111
|
+
### on()
|
|
112
|
+
|
|
113
|
+
> **on**(`type`, `func`): `void`
|
|
114
|
+
|
|
115
|
+
Defined in: src/threads/ThreadPool.ts:251
|
|
116
|
+
|
|
117
|
+
Registers a new callback function to be notified when the given event type is fired.
|
|
118
|
+
|
|
119
|
+
#### Parameters
|
|
120
|
+
|
|
121
|
+
##### type
|
|
122
|
+
|
|
123
|
+
`string`
|
|
124
|
+
|
|
125
|
+
The event type to be notified of. Possible values are: `error`, `exit` and `message`.
|
|
126
|
+
|
|
127
|
+
##### func
|
|
128
|
+
|
|
129
|
+
[`WorkerCallback`](../type-aliases/WorkerCallback.md)
|
|
130
|
+
|
|
131
|
+
The callback function to register.
|
|
132
|
+
|
|
133
|
+
#### Returns
|
|
134
|
+
|
|
135
|
+
`void`
|
|
136
|
+
|
|
137
|
+
***
|
|
138
|
+
|
|
139
|
+
### send()
|
|
140
|
+
|
|
141
|
+
> **send**(`msg`): `void`
|
|
142
|
+
|
|
143
|
+
Defined in: src/threads/ThreadPool.ts:264
|
|
144
|
+
|
|
145
|
+
Sends the provided message to the next available worker thread. Messages are sent in a round-robin order.
|
|
146
|
+
|
|
147
|
+
#### Parameters
|
|
148
|
+
|
|
149
|
+
##### msg
|
|
150
|
+
|
|
151
|
+
`any`
|
|
152
|
+
|
|
153
|
+
The message to send the next available worker thread.
|
|
154
|
+
|
|
155
|
+
#### Returns
|
|
156
|
+
|
|
157
|
+
`void`
|
|
158
|
+
|
|
159
|
+
***
|
|
160
|
+
|
|
161
|
+
### sendAll()
|
|
162
|
+
|
|
163
|
+
> **sendAll**(`msg`): `void`
|
|
164
|
+
|
|
165
|
+
Defined in: src/threads/ThreadPool.ts:279
|
|
166
|
+
|
|
167
|
+
Sends the provided message to all worker threads in the pool.
|
|
168
|
+
|
|
169
|
+
#### Parameters
|
|
170
|
+
|
|
171
|
+
##### msg
|
|
172
|
+
|
|
173
|
+
`any`
|
|
174
|
+
|
|
175
|
+
The message to send to all workers.
|
|
176
|
+
|
|
177
|
+
#### Returns
|
|
178
|
+
|
|
179
|
+
`void`
|
|
180
|
+
|
|
181
|
+
***
|
|
182
|
+
|
|
183
|
+
### sendTo()
|
|
184
|
+
|
|
185
|
+
> **sendTo**(`id`, `msg`): `void`
|
|
186
|
+
|
|
187
|
+
Defined in: src/threads/ThreadPool.ts:290
|
|
188
|
+
|
|
189
|
+
Sends the provided message to the worker thread with the specified id.
|
|
190
|
+
|
|
191
|
+
#### Parameters
|
|
192
|
+
|
|
193
|
+
##### id
|
|
194
|
+
|
|
195
|
+
`number`
|
|
196
|
+
|
|
197
|
+
The id of the thread to send the message to.
|
|
198
|
+
|
|
199
|
+
##### msg
|
|
200
|
+
|
|
201
|
+
`any`
|
|
202
|
+
|
|
203
|
+
The message to send the next available worker thread.
|
|
204
|
+
|
|
205
|
+
#### Returns
|
|
206
|
+
|
|
207
|
+
`void`
|
|
208
|
+
|
|
209
|
+
***
|
|
210
|
+
|
|
211
|
+
### start()
|
|
212
|
+
|
|
213
|
+
> **start**(`options?`, `num?`): `Promise`\<`void`\>
|
|
214
|
+
|
|
215
|
+
Defined in: src/threads/ThreadPool.ts:177
|
|
216
|
+
|
|
217
|
+
Initializes the thread pool with the initial worker threads and begins execution.
|
|
218
|
+
|
|
219
|
+
#### Parameters
|
|
220
|
+
|
|
221
|
+
##### options?
|
|
222
|
+
|
|
223
|
+
[`WorkerOptions`](../interfaces/WorkerOptions.md)
|
|
224
|
+
|
|
225
|
+
The options to use when creating the worker thread.
|
|
226
|
+
|
|
227
|
+
##### num?
|
|
228
|
+
|
|
229
|
+
`number` = `...`
|
|
230
|
+
|
|
231
|
+
The number of initial threads to create, cannot be greater than max. Default is `max`.
|
|
232
|
+
|
|
233
|
+
#### Returns
|
|
234
|
+
|
|
235
|
+
`Promise`\<`void`\>
|
|
236
|
+
|
|
237
|
+
***
|
|
238
|
+
|
|
239
|
+
### stop()
|
|
240
|
+
|
|
241
|
+
> **stop**(): `Promise`\<`void`\>
|
|
242
|
+
|
|
243
|
+
Defined in: src/threads/ThreadPool.ts:224
|
|
244
|
+
|
|
245
|
+
Stops all running thread executions.
|
|
246
|
+
|
|
247
|
+
#### Returns
|
|
248
|
+
|
|
249
|
+
`Promise`\<`void`\>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
[**@rapidrest/core**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@rapidrest/core](../README.md) / ThreadWorker
|
|
6
|
+
|
|
7
|
+
# Abstract Class: ThreadWorker
|
|
8
|
+
|
|
9
|
+
Defined in: src/threads/ThreadWorker.ts:29
|
|
10
|
+
|
|
11
|
+
Provides a simple abstract interface for creating thread workers when using the `ThreadPool` system.
|
|
12
|
+
|
|
13
|
+
## Author
|
|
14
|
+
|
|
15
|
+
Jean-Philippe Steinmetz
|
|
16
|
+
|
|
17
|
+
## Constructors
|
|
18
|
+
|
|
19
|
+
### Constructor
|
|
20
|
+
|
|
21
|
+
> **new ThreadWorker**(`logger`): `ThreadWorker`
|
|
22
|
+
|
|
23
|
+
Defined in: src/threads/ThreadWorker.ts:32
|
|
24
|
+
|
|
25
|
+
#### Parameters
|
|
26
|
+
|
|
27
|
+
##### logger
|
|
28
|
+
|
|
29
|
+
`any`
|
|
30
|
+
|
|
31
|
+
#### Returns
|
|
32
|
+
|
|
33
|
+
`ThreadWorker`
|
|
34
|
+
|
|
35
|
+
## Properties
|
|
36
|
+
|
|
37
|
+
### logger
|
|
38
|
+
|
|
39
|
+
> `protected` **logger**: `any`
|
|
40
|
+
|
|
41
|
+
Defined in: src/threads/ThreadWorker.ts:30
|
|
42
|
+
|
|
43
|
+
## Methods
|
|
44
|
+
|
|
45
|
+
### onMessage()
|
|
46
|
+
|
|
47
|
+
> `abstract` **onMessage**(`msg`): `void` \| `Promise`\<`void`\>
|
|
48
|
+
|
|
49
|
+
Defined in: src/threads/ThreadWorker.ts:41
|
|
50
|
+
|
|
51
|
+
Callback function when a message is received from the thread pool manager.
|
|
52
|
+
|
|
53
|
+
#### Parameters
|
|
54
|
+
|
|
55
|
+
##### msg
|
|
56
|
+
|
|
57
|
+
[`WorkerMessage`](../interfaces/WorkerMessage.md)
|
|
58
|
+
|
|
59
|
+
The message that was received.
|
|
60
|
+
|
|
61
|
+
#### Returns
|
|
62
|
+
|
|
63
|
+
`void` \| `Promise`\<`void`\>
|
|
64
|
+
|
|
65
|
+
***
|
|
66
|
+
|
|
67
|
+
### start()
|
|
68
|
+
|
|
69
|
+
> `abstract` **start**(): `void` \| `Promise`\<`void`\>
|
|
70
|
+
|
|
71
|
+
Defined in: src/threads/ThreadWorker.ts:46
|
|
72
|
+
|
|
73
|
+
Starts execution of the thread worker.
|
|
74
|
+
|
|
75
|
+
#### Returns
|
|
76
|
+
|
|
77
|
+
`void` \| `Promise`\<`void`\>
|
|
78
|
+
|
|
79
|
+
***
|
|
80
|
+
|
|
81
|
+
### stop()
|
|
82
|
+
|
|
83
|
+
> `abstract` **stop**(): `void` \| `Promise`\<`void`\>
|
|
84
|
+
|
|
85
|
+
Defined in: src/threads/ThreadWorker.ts:51
|
|
86
|
+
|
|
87
|
+
Stops execution of all work and shuts down the thread worker.
|
|
88
|
+
|
|
89
|
+
#### Returns
|
|
90
|
+
|
|
91
|
+
`void` \| `Promise`\<`void`\>
|