Skip to content

Commit 479d494

Browse files
committed
Add more functions
1 parent 35f1cec commit 479d494

File tree

8 files changed

+258
-173
lines changed

8 files changed

+258
-173
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,7 @@ Experiment to reproduce Erlang style processes in browser. The api follows the o
7070
* `is_alive(pid)` - Returns if the given pid is alive
7171
* `make_ref()` - Returns a unique reference
7272
* `list()` - Returns a list of all the pids
73+
* `monitor(pid)` - Monitors the given process
74+
* `demonitor(ref)` - Removes the monitor
7375

7476
* `ProcessSystem.run(fun, args, context = null)` - A static generator function used to wrap a normal function or generator. If fun is a function, it returns the value, if it's a generator, then it delegates yielding to the generator.

examples/send_receive.js

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,35 @@
11
"use strict";
22

3-
import { ProcessSystem, GenServer, Application } from "../src/processes";
3+
import { ProcessSystem } from "../src/processes";
44
self.system = self.system || new ProcessSystem();
55

6-
let myApp = {
7-
start: function(type, args){
8-
let pid = self.system.spawn(function*(){
9-
var pid1 = self.system.spawn_link(function*(){
10-
while(true){
6+
let pid = self.system.spawn(function*(){
7+
var pid1 = self.system.spawn_link(function*(){
8+
while(true){
119

12-
yield self.system.receive(function(value){
13-
return console.log(value);
14-
});
15-
16-
self.system.send(pid2, "message from 1");
17-
}
10+
yield self.system.receive(function(value){
11+
return console.log(value);
1812
});
1913

20-
self.system.register("Sally", pid1);
14+
self.system.send(pid2, "message from 1");
15+
}
16+
});
2117

18+
self.system.register("Sally", pid1);
2219

23-
var pid2 = self.system.spawn_link(function*(){
24-
while(true){
25-
26-
self.system.send("Sally", "message from 2");
2720

28-
yield self.system.receive(function(value){
29-
return console.log(value);
30-
});
31-
}
32-
});
21+
var pid2 = self.system.spawn_link(function*(){
22+
while(true){
3323

34-
yield self.system.receive(function(value){
35-
return Symbol.for("no_match");
36-
});
37-
});
24+
self.system.send("Sally", "message from 2");
3825

39-
return [Symbol.for("ok"), pid];
40-
}
41-
};
26+
yield self.system.receive(function(value){
27+
return console.log(value);
28+
});
29+
}
30+
});
4231

43-
let pid = Application.start(myApp);
32+
yield self.system.receive(function(value){
33+
return Symbol.for("no_match");
34+
});
35+
});

gulpfile.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ const babelConfig = {
2020
"transform-es2015-parameters",
2121
"transform-es2015-shorthand-properties",
2222
"transform-es2015-spread",
23-
"transform-es2015-unicode-regex",
24-
"transform-flow-strip-types",
25-
"syntax-flow"
23+
"transform-es2015-unicode-regex"
2624
]
2725
};
2826

0 commit comments

Comments
 (0)