flok 0.0.36 → 0.0.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -0
- data/app/drivers/chrome/build_context.rb +1 -1
- data/app/drivers/chrome/config.yml +10 -0
- data/app/drivers/chrome/pipe.rb +24 -1
- data/app/drivers/chrome/src/persist.js +29 -0
- data/app/drivers/chrome/src/sockio.js +3 -1
- data/app/drivers/chrome/src/vendor/store2.js +3 -0
- data/app/kern/callout.js +55 -0
- data/app/kern/controller.js +3 -0
- data/app/kern/crc32.js +22 -0
- data/app/kern/dispatch.js +16 -0
- data/app/kern/mod/event.js +3 -0
- data/app/kern/mod/persist.js +1 -0
- data/app/kern/mod/timer.js +5 -0
- data/app/kern/pagers/mem_pager.js +2 -0
- data/app/kern/pagers/sockio_pager.js +66 -0
- data/app/kern/pagers/spec0.js +35 -0
- data/app/kern/pagers/spec1.js +24 -0
- data/app/kern/pagers/spec2.js +31 -0
- data/app/kern/services/test.rb +7 -0
- data/app/kern/services/vm.rb +141 -0
- data/app/kern/spec_helper.js +5 -0
- data/bin/flok +27 -5
- data/docs/callout.md +8 -0
- data/docs/client_api.md +1 -1
- data/docs/compilation.md +14 -8
- data/docs/controllers.md +2 -1
- data/docs/datatypes.md +3 -1
- data/docs/environmentals.md +6 -0
- data/docs/interactive.md +6 -1
- data/docs/kernel_api.md +3 -0
- data/docs/mod/event.md +5 -1
- data/docs/mod/persist.md +14 -31
- data/docs/mod/timer.md +4 -2
- data/docs/project.md +16 -5
- data/docs/scheduling.md +1 -0
- data/docs/services.md +141 -56
- data/docs/services/vm.md +128 -0
- data/docs/services/vm/pagers.md +46 -0
- data/lib/flok/build.rb +11 -16
- data/lib/flok/platform.rb +29 -6
- data/lib/flok/project_template/app/scripts/script.js +3 -0
- data/lib/flok/project_template/app/services/service.rb +1 -0
- data/lib/flok/project_template/config/config.yml +1 -0
- data/lib/flok/project_template/config/platforms/chrome/config.yml +1 -0
- data/lib/flok/project_template/config/services.rb +1 -0
- data/lib/flok/service_compiler_templates/services.js.erb +78 -9
- data/lib/flok/services_compiler.rb +117 -20
- data/lib/flok/user_compiler.rb +14 -6
- data/lib/flok/user_compiler_templates/ctable.js.erb +10 -0
- data/lib/flok/version.rb +1 -1
- data/spec/env/etc.rb +1 -1
- data/spec/env/global.rb +2 -0
- data/spec/env/iface.rb +20 -4
- data/spec/env/kern.rb +8 -3
- data/spec/etc/cli_spec.rb +319 -165
- data/spec/etc/lib/assets/config.yml +3 -0
- data/spec/etc/lib/platform_spec.rb +14 -10
- data/spec/etc/lib/project_spec.rb +22 -0
- data/spec/etc/service_compiler/config0.rb +1 -0
- data/spec/etc/service_compiler/config1.rb +1 -0
- data/spec/etc/service_compiler/config2.rb +3 -0
- data/spec/etc/service_compiler/service0.rb +22 -6
- data/spec/etc/service_compiler/service1.rb +26 -0
- data/spec/etc/service_compiler/service_bad_type.rb +20 -0
- data/spec/etc/services_compiler_spec.rb +35 -16
- data/spec/etc/user_compiler/data.js +2 -0
- data/spec/etc/user_compiler_spec.rb +7 -1
- data/spec/iface/driver/persist_spec.rb +106 -0
- data/spec/iface/driver/pipe_spec.rb +5 -0
- data/spec/iface/kern/ping_spec.rb +4 -3
- data/spec/kern/assets/blank.rb +0 -0
- data/spec/kern/assets/service0.rb +24 -0
- data/spec/kern/assets/service1.rb +22 -0
- data/spec/kern/assets/service2.rb +27 -0
- data/spec/kern/assets/service_config0.rb +2 -0
- data/spec/kern/assets/service_config1.rb +2 -0
- data/spec/kern/assets/service_controller0.rb +13 -0
- data/spec/kern/assets/service_controller1.rb +32 -0
- data/spec/kern/assets/service_controller2.rb +38 -0
- data/spec/kern/assets/service_controller3.rb +38 -0
- data/spec/kern/assets/vm/config0.rb +2 -0
- data/spec/kern/assets/vm/config1.rb +12 -0
- data/spec/kern/assets/vm/config2.rb +12 -0
- data/spec/kern/assets/vm/config3.rb +12 -0
- data/spec/kern/assets/vm/controller0.rb +8 -0
- data/spec/kern/assets/vm/controller1.rb +18 -0
- data/spec/kern/assets/vm/controller2.rb +18 -0
- data/spec/kern/assets/vm/controller3.rb +20 -0
- data/spec/kern/assets/vm/controller4.rb +22 -0
- data/spec/kern/assets/vm/controller5.rb +22 -0
- data/spec/kern/assets/vm/controller6.rb +21 -0
- data/spec/kern/assets/vm/service0.rb +24 -0
- data/spec/kern/assets/vm/service_controller0.rb +7 -0
- data/spec/kern/callout_spec.rb +153 -0
- data/spec/kern/functions_spec.rb +29 -0
- data/spec/kern/service_controller_spec.rb +213 -0
- data/spec/kern/vm_service_spec.rb +195 -0
- metadata +98 -12
- data/app/kern/services/rest.rb +0 -310
- data/app/kern/services/timer.rb +0 -30
- data/docs/services/timer.md +0 -21
- data/spec/kern/assets/rest_service.rb +0 -20
- data/spec/kern/assets/timer_service.rb +0 -19
- data/spec/kern/timer_service_spec.rb +0 -40
@@ -0,0 +1,22 @@
|
|
1
|
+
service :my_service do
|
2
|
+
on_wakeup %{
|
3
|
+
every_ticks = 0;
|
4
|
+
on_wakeup_called = true;
|
5
|
+
}
|
6
|
+
|
7
|
+
on_sleep %{
|
8
|
+
on_sleep_called = true;
|
9
|
+
}
|
10
|
+
|
11
|
+
on_connect %{
|
12
|
+
on_connect_called = true;
|
13
|
+
}
|
14
|
+
|
15
|
+
on_disconnect %{
|
16
|
+
on_disconnect_called = true;
|
17
|
+
}
|
18
|
+
|
19
|
+
every 1.seconds, %{
|
20
|
+
every_ticks += 1;
|
21
|
+
}
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
service :my_service do
|
2
|
+
on_wakeup %{
|
3
|
+
}
|
4
|
+
|
5
|
+
on_sleep %{
|
6
|
+
}
|
7
|
+
|
8
|
+
on_connect %{
|
9
|
+
connect_bp = bp;
|
10
|
+
connect_sessions = Object.keys(sessions);
|
11
|
+
}
|
12
|
+
|
13
|
+
on_disconnect %{
|
14
|
+
disconnect_bp = bp;
|
15
|
+
disconnect_sessions = Object.keys(sessions);
|
16
|
+
}
|
17
|
+
|
18
|
+
every 1.seconds, %{
|
19
|
+
every_ticks_sessions = Object.keys(sessions);
|
20
|
+
}
|
21
|
+
|
22
|
+
on "ping", %{
|
23
|
+
ping_bp = bp;
|
24
|
+
ping_params = params;
|
25
|
+
ping_sessions = Object.keys(sessions);
|
26
|
+
}
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
controller :my_controller do
|
2
|
+
spots "hello", "world"
|
3
|
+
|
4
|
+
action :my_action do
|
5
|
+
on_entry %{
|
6
|
+
Embed("my_other_controller", "hello", {});
|
7
|
+
}
|
8
|
+
|
9
|
+
on "next", %{
|
10
|
+
Goto("my_other_action");
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
action :my_other_action do
|
15
|
+
on_entry %{
|
16
|
+
}
|
17
|
+
|
18
|
+
on "next", %{
|
19
|
+
Goto("my_action");
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
controller :my_other_controller do
|
26
|
+
services :spec
|
27
|
+
|
28
|
+
action :my_action do
|
29
|
+
on_entry %{
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
controller :my_controller do
|
2
|
+
spots "hello", "world"
|
3
|
+
|
4
|
+
action :my_action do
|
5
|
+
on_entry %{
|
6
|
+
Embed("my_other_controller", "hello", {});
|
7
|
+
}
|
8
|
+
|
9
|
+
on "next", %{
|
10
|
+
Goto("my_other_action");
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
action :my_other_action do
|
15
|
+
on_entry %{
|
16
|
+
}
|
17
|
+
|
18
|
+
on "next", %{
|
19
|
+
Goto("my_action");
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
controller :my_other_controller do
|
26
|
+
services :spec
|
27
|
+
|
28
|
+
action :my_action do
|
29
|
+
on_entry %{
|
30
|
+
my_base = __base__;
|
31
|
+
var info = {
|
32
|
+
hello: "world"
|
33
|
+
}
|
34
|
+
Request("spec", "ping", info);
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
controller :my_controller do
|
2
|
+
spots "hello", "world"
|
3
|
+
|
4
|
+
action :my_action do
|
5
|
+
on_entry %{
|
6
|
+
Embed("my_other_controller", "hello", {});
|
7
|
+
}
|
8
|
+
|
9
|
+
on "next", %{
|
10
|
+
Goto("my_other_action");
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
action :my_other_action do
|
15
|
+
on_entry %{
|
16
|
+
}
|
17
|
+
|
18
|
+
on "next", %{
|
19
|
+
Goto("my_action");
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
controller :my_other_controller do
|
26
|
+
services :spec
|
27
|
+
|
28
|
+
action :my_action do
|
29
|
+
on_entry %{
|
30
|
+
my_base = __base__;
|
31
|
+
var info = {
|
32
|
+
hello: "world"
|
33
|
+
}
|
34
|
+
Request("no_such_service", "ping", info);
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
controller :my_controller do
|
2
|
+
services :vm
|
3
|
+
|
4
|
+
action :my_action do
|
5
|
+
on_entry %{
|
6
|
+
var info = {
|
7
|
+
ns: "user",
|
8
|
+
key: 33,
|
9
|
+
value: 22
|
10
|
+
};
|
11
|
+
|
12
|
+
Request("vm", "write", info);
|
13
|
+
Request("vm", "read", info);
|
14
|
+
}
|
15
|
+
|
16
|
+
on "read_res", %{
|
17
|
+
read_res_params = params;
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
controller :my_controller do
|
2
|
+
services :vm
|
3
|
+
|
4
|
+
action :my_action do
|
5
|
+
on_entry %{
|
6
|
+
var info = {
|
7
|
+
ns: "user",
|
8
|
+
key: 33,
|
9
|
+
value: 22
|
10
|
+
};
|
11
|
+
|
12
|
+
Request("vm", "write", info);
|
13
|
+
Request("vm", "read", info);
|
14
|
+
Request("vm", "read", info);
|
15
|
+
Request("vm", "read_sync", info);
|
16
|
+
}
|
17
|
+
|
18
|
+
on "read_res", %{
|
19
|
+
read_res_params = params;
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
controller :my_controller do
|
2
|
+
services :vm
|
3
|
+
|
4
|
+
action :my_action do
|
5
|
+
on_entry %{
|
6
|
+
//Send a request
|
7
|
+
var info = {
|
8
|
+
ns: "user",
|
9
|
+
key: "my_key",
|
10
|
+
value: "my_value"
|
11
|
+
};
|
12
|
+
|
13
|
+
read_res_called_with = [];
|
14
|
+
Request("vm", "read", info);
|
15
|
+
Request("vm", "read", info);
|
16
|
+
}
|
17
|
+
|
18
|
+
on "read_res", %{
|
19
|
+
read_res_called_with.push(params);
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
controller :my_controller do
|
2
|
+
services :vm
|
3
|
+
|
4
|
+
action :my_action do
|
5
|
+
on_entry %{
|
6
|
+
//Send a request
|
7
|
+
var info = {
|
8
|
+
ns: "user",
|
9
|
+
key: "my_key"
|
10
|
+
};
|
11
|
+
|
12
|
+
read_res_called_with = [];
|
13
|
+
Request("vm", "read", info);
|
14
|
+
Request("vm", "watch", info);
|
15
|
+
}
|
16
|
+
|
17
|
+
on "read_res", %{
|
18
|
+
read_res_called_with.push(params);
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
service :my_service do
|
2
|
+
on_wakeup %{
|
3
|
+
on_wakeup_called = true;
|
4
|
+
}
|
5
|
+
|
6
|
+
on_sleep %{
|
7
|
+
on_sleep_called = true;
|
8
|
+
}
|
9
|
+
|
10
|
+
on_connect %{
|
11
|
+
on_connect_called = true;
|
12
|
+
}
|
13
|
+
|
14
|
+
on_disconnect %{
|
15
|
+
on_disconnect_called = true;
|
16
|
+
}
|
17
|
+
|
18
|
+
every 1.seconds, %{
|
19
|
+
for (var i = 0; i < Object.keys(sessions).length; ++i) {
|
20
|
+
var bp = Object.keys(sessions)[i];
|
21
|
+
int_event(bp, "ping", {});
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
Dir.chdir File.join File.dirname(__FILE__), '../../'
|
2
|
+
require './spec/env/kern.rb'
|
3
|
+
require './spec/lib/helpers.rb'
|
4
|
+
require './spec/lib/io_extensions.rb'
|
5
|
+
require './spec/lib/rspec_extensions.rb'
|
6
|
+
|
7
|
+
RSpec.describe "kern:timer_service_spec" do
|
8
|
+
include_context "kern"
|
9
|
+
|
10
|
+
it "Can register for single-shot a callout event 1 tick in the future" do
|
11
|
+
#Compile the controller
|
12
|
+
ctx = flok_new_user File.read('./spec/kern/assets/blank.rb')
|
13
|
+
|
14
|
+
#Register callout
|
15
|
+
ctx.eval %{
|
16
|
+
//Can accept an event via int_event
|
17
|
+
function event_handler(ep, ename, info) {
|
18
|
+
event_handler_ep = ep;
|
19
|
+
event_handler_ename = ename;
|
20
|
+
}
|
21
|
+
reg_evt(9, event_handler);
|
22
|
+
|
23
|
+
//Send the 'test' event in one tick to the 9 event function
|
24
|
+
reg_timeout(9, "test", 1);
|
25
|
+
}
|
26
|
+
|
27
|
+
@driver.int("int_timer")
|
28
|
+
|
29
|
+
ep = ctx.eval("event_handler_ep")
|
30
|
+
ename = ctx.eval("event_handler_ename")
|
31
|
+
expect(ep).to eq(9)
|
32
|
+
expect(ename).to eq("test")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "Can register for an interval callout event 1 tick in the future" do
|
36
|
+
#Compile the controller
|
37
|
+
ctx = flok_new_user File.read('./spec/kern/assets/blank.rb')
|
38
|
+
|
39
|
+
#Register callout
|
40
|
+
ctx.eval %{
|
41
|
+
//Can accept an event via int_event
|
42
|
+
times_called = 0;
|
43
|
+
function event_handler(ep, ename, info) {
|
44
|
+
times_called += 1;
|
45
|
+
}
|
46
|
+
reg_evt(9, event_handler);
|
47
|
+
|
48
|
+
//Send the 'test' event in one tick to the 9 event function
|
49
|
+
reg_interval(9, "test", 1);
|
50
|
+
}
|
51
|
+
|
52
|
+
@driver.int("int_timer")
|
53
|
+
@driver.int("int_timer")
|
54
|
+
|
55
|
+
times_called = ctx.eval("times_called")
|
56
|
+
expect(times_called).to eq(2);
|
57
|
+
end
|
58
|
+
|
59
|
+
it "only calls timeout event once" do
|
60
|
+
#Compile the controller
|
61
|
+
ctx = flok_new_user File.read('./spec/kern/assets/blank.rb')
|
62
|
+
|
63
|
+
#Register callout
|
64
|
+
ctx.eval %{
|
65
|
+
//Can accept an event via int_event
|
66
|
+
times_called = 0;
|
67
|
+
function event_handler(ep, ename, info) {
|
68
|
+
times_called += 1;
|
69
|
+
}
|
70
|
+
reg_evt(9, event_handler);
|
71
|
+
|
72
|
+
//Send the 'test' event in one tick to the 9 event function
|
73
|
+
reg_timeout(9, "test", 1);
|
74
|
+
}
|
75
|
+
|
76
|
+
@driver.int("int_timer")
|
77
|
+
@driver.int("int_timer")
|
78
|
+
|
79
|
+
times_called = ctx.eval("times_called")
|
80
|
+
expect(times_called).to eq(1);
|
81
|
+
end
|
82
|
+
|
83
|
+
it "does have nothing left in queue after one timeout" do
|
84
|
+
#Compile the controller
|
85
|
+
ctx = flok_new_user File.read('./spec/kern/assets/blank.rb')
|
86
|
+
|
87
|
+
#Register callout
|
88
|
+
ctx.eval %{
|
89
|
+
//Can accept an event via int_event
|
90
|
+
function event_handler(ep, ename, info) {
|
91
|
+
}
|
92
|
+
reg_evt(9, event_handler);
|
93
|
+
|
94
|
+
//Send the 'test' event in one tick to the 9 event function
|
95
|
+
reg_timeout(9, "test", 1);
|
96
|
+
}
|
97
|
+
|
98
|
+
@driver.int("int_timer")
|
99
|
+
|
100
|
+
res = JSON.parse(ctx.eval("JSON.stringify(callout_queue)"))
|
101
|
+
expect(res).to eq({});
|
102
|
+
end
|
103
|
+
|
104
|
+
it "does have left in queue after interval" do
|
105
|
+
#Compile the controller
|
106
|
+
ctx = flok_new_user File.read('./spec/kern/assets/blank.rb')
|
107
|
+
|
108
|
+
#Register callout
|
109
|
+
ctx.eval %{
|
110
|
+
//Can accept an event via int_event
|
111
|
+
function event_handler(ep, ename, info) {
|
112
|
+
}
|
113
|
+
reg_evt(9, event_handler);
|
114
|
+
|
115
|
+
//Send the 'test' event in one tick to the 9 event function
|
116
|
+
reg_interval(9, "test", 1);
|
117
|
+
}
|
118
|
+
|
119
|
+
@driver.int("int_timer")
|
120
|
+
|
121
|
+
res = JSON.parse(ctx.eval("JSON.stringify(callout_queue)"))
|
122
|
+
expect(res).not_to eq({});
|
123
|
+
end
|
124
|
+
|
125
|
+
it "does NOT have left in queue after interval if event receiver is gone" do
|
126
|
+
#Compile the controller
|
127
|
+
ctx = flok_new_user File.read('./spec/kern/assets/blank.rb')
|
128
|
+
|
129
|
+
#Register callout
|
130
|
+
ctx.eval %{
|
131
|
+
//Can accept an event via int_event
|
132
|
+
times_called = 0;
|
133
|
+
function event_handler(ep, ename, info) {
|
134
|
+
times_called += 1;
|
135
|
+
}
|
136
|
+
reg_evt(9, event_handler);
|
137
|
+
|
138
|
+
//Send the 'test' event in one tick to the 9 event function
|
139
|
+
reg_interval(9, "test", 1);
|
140
|
+
}
|
141
|
+
|
142
|
+
@driver.int("int_timer")
|
143
|
+
|
144
|
+
ctx.eval "dereg_evt(9);"
|
145
|
+
@driver.int("int_timer")
|
146
|
+
|
147
|
+
times_called = ctx.eval("times_called")
|
148
|
+
expect(times_called).to eq(1);
|
149
|
+
|
150
|
+
res = JSON.parse(ctx.eval("JSON.stringify(callout_queue)"))
|
151
|
+
expect(res).to eq({});
|
152
|
+
end
|
153
|
+
end
|