@moskva/runtime 0.1.0
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/IRunnable.js +11 -0
- package/changes.md +6 -0
- package/index.js +14 -0
- package/lib/Test.js +18 -0
- package/lib/index.js +1 -0
- package/package.json +4 -0
- package/readme.md +89 -0
- package/readme0.md +56 -0
- package/test/index.js +31 -0
package/IRunnable.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class IRunnable {
|
|
2
|
+
/**
|
|
3
|
+
* Execute an operation
|
|
4
|
+
* @param {!Function} op
|
|
5
|
+
* @param {...object} params
|
|
6
|
+
*/
|
|
7
|
+
run(op, ...params){
|
|
8
|
+
//
|
|
9
|
+
}
|
|
10
|
+
} // in normal js, not possible to invoke the class without new operator,
|
|
11
|
+
// in the advanced JavaScript it'd be possible to invoke interface directly.
|
package/changes.md
ADDED
package/index.js
ADDED
package/lib/Test.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var { FnImplFactory } = require('@javish/lib')
|
|
2
|
+
|
|
3
|
+
var RunnableTest = FnImplFactory(
|
|
4
|
+
class RunnableTest {
|
|
5
|
+
__fm() {
|
|
6
|
+
return this.run
|
|
7
|
+
}
|
|
8
|
+
/** The test list @type {string[]} */
|
|
9
|
+
test = []
|
|
10
|
+
/** Run an operation */
|
|
11
|
+
run() {}
|
|
12
|
+
}, ({
|
|
13
|
+
run() {
|
|
14
|
+
console.warn('[run] not implemented for test')
|
|
15
|
+
}
|
|
16
|
+
}))
|
|
17
|
+
|
|
18
|
+
module.exports = RunnableTest
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports.Runnable=require('./Test')
|
package/package.json
ADDED
package/readme.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Runtime Moskva
|
|
2
|
+
|
|
3
|
+
This runtime provides callable instances of `Runnable` functional interfaces. A
|
|
4
|
+
`Runnable` is a class instance that can be invoked like a function.
|
|
5
|
+
|
|
6
|
+
```js
|
|
7
|
+
interface IRunnable {
|
|
8
|
+
run() {}
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
<!-- Instances are allocated memory and can request compute via the event loop. -->
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
An example below shows that even though `runner` is an instance, it can still be
|
|
17
|
+
invoked as a function:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
var{Runnable}=require('@moskva/runtime')
|
|
21
|
+
|
|
22
|
+
var runner=new class extends Runnable {
|
|
23
|
+
const(){
|
|
24
|
+
this.test=[]
|
|
25
|
+
this.test.push(new Date)
|
|
26
|
+
}
|
|
27
|
+
test2(){
|
|
28
|
+
return this.test
|
|
29
|
+
}
|
|
30
|
+
run(){
|
|
31
|
+
console.log(' < Hello runner; test =',this.test2())
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.log('calling runner:')
|
|
36
|
+
runner()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
created new functional [class Runnable]
|
|
41
|
+
calling runner:
|
|
42
|
+
< Hello runner; test = [ 2026-01-27T23:19:34.106Z ]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
var runner2 = new class extends Runnable {
|
|
49
|
+
// can't use fieldss / constructor
|
|
50
|
+
// new_field = []
|
|
51
|
+
const() {
|
|
52
|
+
this.test=['test']
|
|
53
|
+
}
|
|
54
|
+
run() {
|
|
55
|
+
console.log(' < Hello runner2; test =',this.test)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
console.log('calling runner2:')
|
|
60
|
+
runner2()
|
|
61
|
+
```
|
|
62
|
+
```sh
|
|
63
|
+
calling runner2:
|
|
64
|
+
< Hello runner2; test = [ 'test' ]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Instances of standard, non-runnable classes cannot be invoked. This behaviour is
|
|
68
|
+
only available when extending `Runnable`.
|
|
69
|
+
|
|
70
|
+
## Implementation requirements
|
|
71
|
+
|
|
72
|
+
* The `run` method **must** be implemented. It is the entry point invoked when
|
|
73
|
+
the instance is called.
|
|
74
|
+
* The implementation can access additional internal APIs via `this`.
|
|
75
|
+
|
|
76
|
+
## Initialisation rules
|
|
77
|
+
|
|
78
|
+
Instance fields must be initialised inside the `const` method.
|
|
79
|
+
|
|
80
|
+
Class field syntax is not supported. The implementation relies on a proxy, and
|
|
81
|
+
constructing a `Runnable` with field initialisers would cause infinite
|
|
82
|
+
recursion. There is currently no safe way to intercept or extract field
|
|
83
|
+
initialisers.
|
|
84
|
+
|
|
85
|
+
Unless a viable solution is found, this limitation will remain.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
(c) 2026
|
package/readme0.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Runtime Moskva
|
|
2
|
+
|
|
3
|
+
This runtime is the creation of instances of _Runnable_ functional interfaces,
|
|
4
|
+
i.e., classes that can be run as functions directly.
|
|
5
|
+
|
|
6
|
+
<!-- that are
|
|
7
|
+
allocated some memory and can request compute via the event loop. -->
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
interface IRunnable {
|
|
11
|
+
run() {}
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
<!--
|
|
16
|
+
It can run those in isolates, i.e., threads on the same process that share
|
|
17
|
+
access to host AOT memory. -->
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
For example, even if the new _RunnerExt_ is an instance, it can still be run a
|
|
22
|
+
function as shown below:
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
var{Runnable}=require('@moskva/runtime')
|
|
27
|
+
|
|
28
|
+
var runner = new class runner extends Runnable {
|
|
29
|
+
const() {
|
|
30
|
+
this.test.push(new Date)
|
|
31
|
+
}
|
|
32
|
+
test2() {
|
|
33
|
+
return this.test
|
|
34
|
+
}
|
|
35
|
+
run() {
|
|
36
|
+
console.log(' < Hello runner ext; test =',this.test2())
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
console.log('calling runner ext:')
|
|
41
|
+
runner()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Instances of standard, non-runnable classes cannot be invoked, unlike when using
|
|
45
|
+
the Runnable superclass.
|
|
46
|
+
|
|
47
|
+
Implementation requirements: implement the `run` method that will be invoked
|
|
48
|
+
while the impementation can access additional `this` apis internally.
|
|
49
|
+
|
|
50
|
+
To initialise the instance variables (fields), they must be instantiated in
|
|
51
|
+
const method, as the fields syntax won't work as the solution is based on proxy
|
|
52
|
+
and attempting to construct a Runnable would create an infinite recursion and
|
|
53
|
+
there's no way to get handle of field initialisers. Unless one is found this
|
|
54
|
+
won't change.
|
|
55
|
+
|
|
56
|
+
---
|
package/test/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var {Runnable} = require('..')
|
|
2
|
+
|
|
3
|
+
var runner = new class extends Runnable {
|
|
4
|
+
const() {
|
|
5
|
+
this.test=[]
|
|
6
|
+
this.test.push(new Date)
|
|
7
|
+
}
|
|
8
|
+
test2() {
|
|
9
|
+
return this.test
|
|
10
|
+
}
|
|
11
|
+
run() {
|
|
12
|
+
// it needs to have this of the runner also
|
|
13
|
+
console.log(' < Hello runner; test =',this.test2())
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
console.log('calling runner:')
|
|
18
|
+
runner()
|
|
19
|
+
|
|
20
|
+
var runner2 = new class extends Runnable {
|
|
21
|
+
const() {
|
|
22
|
+
this.test=['test']
|
|
23
|
+
}
|
|
24
|
+
run() {
|
|
25
|
+
// it needs to have this of the runner also
|
|
26
|
+
console.log(' < Hello runner2; test =',this.test)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log('calling runner2:')
|
|
31
|
+
runner2()
|