Skip to content

Commit 5327acb

Browse files
committed
typescript stuff
1 parent 41c2709 commit 5327acb

3 files changed

Lines changed: 22 additions & 18 deletions

File tree

src/processes/process.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,13 @@ class Process {
2626
flags: Map<symbol, any>
2727
monitors: any[]
2828

29-
constructor(
30-
pid: PID,
31-
func: Function,
32-
args: any[],
33-
mailbox: Mailbox,
34-
system: System
35-
) {
36-
this.pid = pid
29+
constructor(system: System, func: Function, args: any[]) {
30+
this.system = system
3731
this.func = func
3832
this.args = args
39-
this.mailbox = mailbox
40-
this.system = system
4133
this.status = States.STOPPED
34+
this.pid = new PID()
35+
this.mailbox = new Mailbox()
4236
this.dict = new Map()
4337
this.flags = new Map()
4438
this.monitors = []

src/processes/process_system.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,20 +171,18 @@ class ProcessSystem {
171171
linked: boolean,
172172
monitored: boolean
173173
) {
174-
let newpid = new PID()
175-
let mailbox = new Mailbox()
176-
let newproc = new Process(newpid, fun, args, mailbox, this)
174+
let newproc = new Process(this, fun, args)
177175

178-
this.pids.set(newpid, newproc)
179-
this.mailboxes.set(newpid, mailbox)
180-
this.links.set(newpid, new Set())
176+
this.pids.set(newproc.pid, newproc)
177+
this.mailboxes.set(newproc.pid, newproc.mailbox)
178+
this.links.set(newproc.pid, new Set())
181179

182180
if (linked) {
183-
this.link(newpid)
181+
this.link(newproc.pid)
184182
}
185183

186184
if (monitored) {
187-
this.monitor(newpid)
185+
this.monitor(newproc.pid)
188186
}
189187

190188
newproc.start()

test/process_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import test from 'ava'
2+
import Process from '../src/processes/process'
3+
import Mailbox from '../src/processes/mailbox'
4+
import {PID} from 'erlang-types'
5+
6+
test('constructor', function(t) {
7+
const pid = new PID()
8+
const mailbox = new Mailbox()
9+
const process = new Process()
10+
11+
t.is(mailbox.messages.length, 0)
12+
})

0 commit comments

Comments
 (0)