File tree Expand file tree Collapse file tree 4 files changed +95
-22
lines changed Expand file tree Collapse file tree 4 files changed +95
-22
lines changed Original file line number Diff line number Diff line change
1
+ import { PID } from 'erlang-types'
2
+
3
+ class ProcessQueue {
4
+ pid : PID
5
+ tasks : Function [ ]
6
+
7
+ constructor ( pid : PID ) {
8
+ this . pid = pid
9
+ this . tasks = [ ]
10
+ }
11
+
12
+ empty ( ) {
13
+ return this . tasks . length === 0
14
+ }
15
+
16
+ add ( task : any ) {
17
+ this . tasks . push ( task )
18
+ }
19
+
20
+ next ( ) {
21
+ return this . tasks . shift ( )
22
+ }
23
+ }
24
+
25
+ export default ProcessQueue
Original file line number Diff line number Diff line change 1
1
import { PID } from 'erlang-types'
2
-
3
- class ProcessQueue {
4
- pid : PID
5
- tasks : Function [ ]
6
-
7
- constructor ( pid : PID ) {
8
- this . pid = pid
9
- this . tasks = [ ]
10
- }
11
-
12
- empty ( ) {
13
- return this . tasks . length === 0
14
- }
15
-
16
- add ( task : any ) {
17
- this . tasks . push ( task )
18
- }
19
-
20
- next ( ) {
21
- return this . tasks . shift ( )
22
- }
23
- }
2
+ import ProcessQueue from './process_queue'
24
3
25
4
class Scheduler {
26
5
isRunning : boolean
Original file line number Diff line number Diff line change
1
+ import test from 'ava'
2
+ import Mailbox from '../src/processes/mailbox'
3
+
4
+ test ( 'constructor' , function ( t ) {
5
+ const mailbox = new Mailbox ( )
6
+
7
+ t . is ( mailbox . messages . length , 0 )
8
+ } )
9
+
10
+ test ( 'get' , function ( t ) {
11
+ const mailbox = new Mailbox ( )
12
+
13
+ t . is ( mailbox . get ( ) . length , 0 )
14
+
15
+ mailbox . deliver ( 'Hi' )
16
+
17
+ t . is ( mailbox . get ( ) . length , 1 )
18
+ } )
19
+
20
+ test ( 'isEmpty' , function ( t ) {
21
+ const mailbox = new Mailbox ( )
22
+
23
+ t . true ( mailbox . isEmpty ( ) )
24
+
25
+ mailbox . deliver ( 'Hi' )
26
+
27
+ t . false ( mailbox . isEmpty ( ) )
28
+ } )
29
+
30
+ test ( 'removeAt' , function ( t ) {
31
+ const mailbox = new Mailbox ( )
32
+
33
+ mailbox . deliver ( 'Hi' )
34
+ mailbox . deliver ( 'Goodbye' )
35
+
36
+ mailbox . removeAt ( 0 )
37
+
38
+ t . is ( mailbox . get ( ) [ 0 ] , 'Goodbye' )
39
+ } )
Original file line number Diff line number Diff line change
1
+ import test from 'ava'
2
+ import ProcessQueue from '../src/processes/process_queue'
3
+ import { PID } from 'erlang-types'
4
+
5
+ test ( 'constructor' , function ( t ) {
6
+ const pid = new PID ( )
7
+ const queue = new ProcessQueue ( pid )
8
+
9
+ t . is ( queue . pid . id , pid . id )
10
+ t . is ( queue . tasks . length , 0 )
11
+ t . true ( queue . empty ( ) )
12
+ } )
13
+
14
+ test ( 'add' , function ( t ) {
15
+ const pid = new PID ( )
16
+ const queue = new ProcessQueue ( pid )
17
+
18
+ queue . add ( ( ) => 'Hi' )
19
+ t . false ( queue . empty ( ) )
20
+ } )
21
+
22
+ test ( 'next' , function ( t ) {
23
+ const pid = new PID ( )
24
+ const queue = new ProcessQueue ( pid )
25
+ const func = ( ) => 'Hi'
26
+
27
+ queue . add ( func )
28
+
29
+ t . is ( queue . next ( ) , func )
30
+ } )
You can’t perform that action at this time.
0 commit comments