You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-22Lines changed: 14 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,4 @@
1
-
Experiment to reproduce erlang style processes in browser. The api follows the one from Erlang. All are found on the `ProcessSystem` class
2
-
3
-
4
-
### Running Examples
5
-
6
-
*`jspm install`
7
-
*`python -m SimpleHTTPServer 8000`
8
-
9
-
Going to `localhost:8000` will show links to examples.
1
+
Experiment to reproduce Erlang style processes in browser. The api follows the one from Erlang. All are found on the `ProcessSystem` class
10
2
11
3
One example is an implementation of a GenServer. The other example is 2 processes talking
12
4
to each other.
@@ -15,38 +7,38 @@ to each other.
15
7
16
8
* First, import the ProcessSystem create a new instance of one.
17
9
```javascript
18
-
import { ProcessSystem} from"processes";
10
+
constProcessSystem=require("erlang-processes");
19
11
let system =newProcessSystem();
20
12
```
21
-
22
-
* Now you can spawn processes using the system.
13
+
14
+
* Now you can spawn processes using the system.
23
15
24
16
A process will switch to other processes when yield is used and will run until it completes.
25
-
17
+
26
18
```javascript
27
19
var pid1 =system.spawn(function*(){
28
20
while(true){
29
-
21
+
30
22
yieldsystem.receive(function(value){
31
23
returnconsole.log(value);
32
24
});
33
-
25
+
34
26
system.send(pid2, "message from 1");
35
27
}
36
28
});
37
-
29
+
38
30
system.register("Sally", pid1);
39
-
31
+
40
32
var pid2 =system.spawn(function*(){
41
33
while(true){
42
34
system.send("Sally", "message from 2");
43
-
35
+
44
36
yieldsystem.receive(function(value){
45
37
returnconsole.log(value);
46
38
});
47
39
}
48
40
});
49
-
41
+
50
42
```
51
43
52
44
### API
@@ -88,13 +80,13 @@ to each other.
88
80
* `init(args)` - Must return an array containing a symbol and the initial state
89
81
* `handle_call(action, from, state)` - Called when `GenServer.call` is called. This function is given the action, the pid of the calling process, and the current state. Must return `[reply, return_value, new_state]` where reply is a symbol ,usually `Symbol.for("reply"), the value to return to the process, and lastly, the new state of the GenServer.
90
82
* `handle_cast(action, state)` - Called when `GenServer.cast` is called. his function is given the action, and the current state. Must return `[reply, return_value, new_state]` where reply is a symbol ,usually `Symbol.for("noreply")`, and lastly, the new state of the GenServer.
91
-
83
+
92
84
#### GenServer Example
93
85
94
86
An example of a Stack using a GenServer
95
87
96
88
```javascript
97
-
import { ProcessSystem, GenServer } from "processes";
0 commit comments