git ssb

0+

wanderer🌟 / js-primea-abstract-container



Tree: 3c51a3dbfcb5e55cfdcd0b54850b584f04b0f602

Files: 3c51a3dbfcb5e55cfdcd0b54850b584f04b0f602 / index.js

1604 bytesRaw
1module.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 method runs when the container needs to be started up. It cannot be
19 // called before onCreation was successful. It can be called after a shutdown
20 // was requested in onIdle.
21 async onStartup () {
22 throw new Error('Unimplemented startup method')
23 }
24
25 // This is called for each incoming message the container gets.
26 //
27 // Optionally it can return a single value.
28 async onMessage (message) {
29 throw new Error('Unimplemented message: ' + message.data)
30 }
31
32 // onIdle is called when there are no more immediate messages pending
33 // in the incoming queue for the container to receive.
34 //
35 // This can be overriden by a subclass.
36 onIdle () {
37 // This tells the kernel that it is safe to freeze (aka turn off) this container.
38 // This removes all references in memory and the next time this instance is
39 // requested it has to be deserialised from storage and spinned up. This can be
40 // a time consuming operation.
41 this.kernel.shutdown()
42 }
43}
44

Built with git-ssb-web