Files: 736aefeb448384f3c3133922fe104db38ddb2a27 / index.js
1336 bytesRaw
1 | module.exports = class AbstractContainer { |
2 | // The constructor is given an instance of the kernel |
3 | // https://github.com/primea/js-primea-hypervisor/blob/master/docs/kernel.md |
4 | constructor (kernel) { |
5 | this.kernel = kernel |
6 | } |
7 | |
8 | // This method runs once when the container is initially created. |
9 | // |
10 | // In general, a root instance receives no message, but every other instance |
11 | // receives a message with a singel port, which is a channel to its parent (aka the root). |
12 | // |
13 | // Optionally it can return a single value. |
14 | async onCreation (message) { |
15 | throw new Error('Unimplemented initialiser') |
16 | } |
17 | |
18 | // This is called for each incoming message the container gets. |
19 | // |
20 | // Optionally it can return a single value. |
21 | async onMessage (message) { |
22 | throw new Error('Unimplemented message: ' + message.data) |
23 | } |
24 | |
25 | // onIdle is called when there are no more immediate messages pending |
26 | // in the incoming queue for the container to receive. |
27 | // |
28 | // This can be overriden by a subclass. |
29 | onIdle () { |
30 | // This tells the kernel that it is safe to freeze (aka turn off) this container. |
31 | // This removes all references in memory and the next time this instance is |
32 | // requested it has to be deserialised from storage and spinned up. This can be |
33 | // a time consuming operation. |
34 | this.kernel.shutdown() |
35 | } |
36 | } |
37 |
Built with git-ssb-web