git ssb

0+

wanderer🌟 / js-primea-abstract-container



Tree: 51b1ae3e7b8df2defc7722ca143f20adf3199bd1

Files: 51b1ae3e7b8df2defc7722ca143f20adf3199bd1 / index.js

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

Built with git-ssb-web