You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The dispatcher module can be run in multiple different execution modes:
21
+
The context module can be run in multiple different execution modes:
28
22
29
23
- Run-To-Completion
30
24
- Synchronous quantum/time-slicing
31
25
- Asynchronous quantum/time-slicing
32
26
33
-
## Command-Line Interfaces
34
-
35
-
### `hzs` / `hzscript`
36
-
37
-
Execute source code with optional hot-compiling via `stdin`, argument, or file input.
38
-
39
-
#### Command-Line Options
40
-
41
-
`-i`*path* (`--input`)
42
-
43
-
- This option supplies the text from the given filepath as the input JavaScript source code you would like to execute. If this option is set to nothing, or is not set at all, then the source code is consumed via the standard input of the terminal.
44
-
45
-
`-s`*code* (`--source`)
46
-
47
-
- If set, this option specifies the tring which follows as the input JavaScript source code which you would like to execute. If this option is set to nothing, or is not set at all, then the source code is consumed via the standard input of the terminal.
48
-
49
-
`-a`*quantum* (`--async`)
50
-
51
-
- If set, this option specifies the time slice quantum of the dispatcher so that it cooperates with the built-in asynchronous event loop. The dispatcher will pause the running code when the duration of its execution reaches or exceeds the time slice, allowing the event loop to continue operating. 5 milliseconds after pausing, the dispatcher will resume execution until the time slice quantum is reached again.
52
-
53
-
`-c` (`--compile`)
54
-
55
-
- If set, then `hertzscript-compiler` will pre-process the input source code before it is executed. Useful for quick testing without having to manually compile to another file every time you want to execute the script.
56
-
57
-
`--spawn`
58
-
59
-
- If set in addition to the `--compile` option, then `hertzscript-compiler` will be used to detect and compile the `spawn` keyword. If the `--compile` option is not present, then this option will do nothing.
60
-
61
27
---
62
28
63
-
## Dispatcher Module
29
+
## Context Module
64
30
65
-
The dispatcher itself is the main module, so you can import it simply like this:
31
+
The context itself is the main module, so you can import it simply like this:
Imports a pre-compiled HertzScript Module into the dispatcher, spawning it as a new coroutine. The module is not immediately executed with this method and is only enqueued for later execution.
41
+
Imports a pre-compiled HertzScript Module into the context, spawning it as a new coroutine. The module is not immediately executed with this method and is only enqueued for later execution.
76
42
77
43
#### Function Parameters
78
44
79
45
```JavaScript
80
-
dispatcher.import( hzModule );
46
+
context.import( hzModule );
81
47
```
82
48
83
49
`hzModule` Function
84
50
85
51
- A `Function` which was previously compiled with `hertzscript-compiler` in `module` mode.
86
52
87
-
### `Dispatcher.prototype.exec`
53
+
### `Context.prototype.exec`
88
54
89
55
This method immediately executes the given pre-compiled function or HzModule in run-to-completion mode.
90
56
@@ -95,7 +61,7 @@ The returned value is the last value returned by the top-most function.
- An optional array to supply as arguments when calling `functor`.
134
100
135
-
### `Dispatcher.prototype.enqueue`
101
+
### `Context.prototype.enqueue`
136
102
137
103
Adds a pre-compiled function to the end of the active coroutine's call stack, or creates a new coroutine for it if there is no active coroutine. The coroutine is not immediately executed with this method and is only enqueued for later execution.
- A timeslice quantum, in milliseconds, which specifies the approximate maximum length of time the dispatcher should cycle.
139
+
- A timeslice quantum, in milliseconds, which specifies the approximate maximum length of time the context should cycle.
174
140
175
141
`throwUp` (*Optional*) Boolean
176
142
177
-
- This argument affects how the dispatcher handles uncaught errors. If set to `true` then the dispatcher will stop cycling and re-throw any uncaught errors, otherwise it will terminate the active coroutine and continue cycling.
143
+
- This argument affects how the context handles uncaught errors. If set to `true` then the context will stop cycling and re-throw any uncaught errors, otherwise it will terminate the active coroutine and continue cycling.
178
144
179
-
### `Dispatcher.prototype.runSync`
145
+
### `Context.prototype.runSync`
180
146
181
-
Sets the dispatcher to running state and cycles it for a given duration.
147
+
Sets the context to running state and cycles it for a given duration.
182
148
183
149
#### Return Value
184
150
@@ -187,46 +153,20 @@ The returned value is the last value returned in the most recent cycle.
- A timeslice quantum, in milliseconds, which specifies the approximate maximum length of time the dispatcher should cycle. If set to `false` then the dispatcher will continue cycling until all coroutines have finished executing.
161
+
- A timeslice quantum, in milliseconds, which specifies the approximate maximum length of time the context should cycle. If set to `false` then the context will continue cycling until all coroutines have finished executing.
196
162
197
163
`throwUp` (*Optional*) Boolean
198
164
199
-
- This argument affects how the dispatcher handles uncaught errors. If set to `true` then the dispatcher will stop cycling and re-throw any uncaught errors, otherwise it will terminate the active coroutine and continue cycling.
165
+
- This argument affects how the context handles uncaught errors. If set to `true` then the context will stop cycling and re-throw any uncaught errors, otherwise it will terminate the active coroutine and continue cycling.
200
166
201
-
### `Dispatcher.prototype.runAsync`
167
+
### `Context.prototype.dispatchAll`
202
168
203
-
Sets the dispatcher to running state and cycles it for a given duration in a given interval, scheduling cycles in the acynchronous event loop using `setTimeout`. Can be stopped via `Dispatcher.prototype.stop`.
204
-
205
-
#### Return Value
206
-
207
-
Either a `Promise` which resolves with the returned value is the last value returned by the top-most function, or `undefined` if this method is already running.
- A cycle delay, in milliseconds, which specifies the length of time to wait in between cycles. During this time, other functions in the asynchronous event loop may execute.
218
-
219
-
`quantum` (*Optional*) Number
220
-
221
-
- A timeslice quantum, in milliseconds, which specifies the approximate maximum length of time the dispatcher should cycle per-interval.
222
-
223
-
`throwUp` (*Optional*) Boolean
224
-
225
-
- This argument affects how the dispatcher handles uncaught errors. If set to `true` then the dispatcher will stop cycling and re-throw any uncaught errors, otherwise it will terminate the active coroutine and continue cycling.
226
-
227
-
### `Dispatcher.prototype.runComplete`
228
-
229
-
Sets the dispatcher to running state and cycles it in run-to-completion mode, only returning when all coroutines have finished executing.
169
+
Sets the context to running state and cycles it in run-to-completion mode, only returning when all coroutines have finished executing.
230
170
231
171
#### Return Value
232
172
@@ -235,13 +175,9 @@ The returned value is the last value returned by the top-most function.
235
175
#### Function Parameters
236
176
237
177
```JavaScript
238
-
dispatcher.runComplete( [ throwUp =false ] );
178
+
context.dispatchAll( [ throwUp =false ] );
239
179
```
240
180
241
181
`throwUp` (*Optional*) Boolean
242
182
243
-
- This argument affects how the dispatcher handles uncaught errors. If set to `true` then the dispatcher will stop cycling and re-throw any uncaught errors, otherwise it will terminate the active coroutine and continue cycling.
244
-
245
-
### `Dispatcher.prototype.stop`
246
-
247
-
Stops the dispatcher from cycling, then resets the runqueue's `blockIndex` and `activeBlock`. Can be used to stop `runAsync`.
183
+
- This argument affects how the context handles uncaught errors. If set to `true` then the context will stop cycling and re-throw any uncaught errors, otherwise it will terminate the active coroutine and continue cycling.
0 commit comments