Skip to content

Commit 59da1f7

Browse files
committed
fix runtime errors
1 parent b43c5cb commit 59da1f7

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/chapter7/q2/CallHandler.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,30 @@ export class CallHandler {
2424
* employeeLevels[1] = managers
2525
* employeeLevels[2] = directors
2626
*/
27-
this.employeeLevels = new Array(LEVELS);
27+
this.employeeLevels = [];
28+
29+
this.callQueues = [];
2830
/* queues for each call�s rank */
29-
this.callQueues = new Array(LEVELS);
30-
31+
for(let i = 0; i < LEVELS; i++){
32+
this.callQueues.push([]);
33+
}
34+
3135
// Create respondents.
32-
let respondents = new Array(NUM_RESPONDENTS);
36+
let respondents = [];
3337
for (let k = 0; k < NUM_RESPONDENTS - 1; k++) {
3438
respondents.push(new Respondent(this));
3539
}
36-
this.employeeLevels[0] = respondents;
40+
this.employeeLevels.push(respondents);
3741

3842
// Create managers.
39-
let managers = new Array(NUM_MANAGERS);
43+
let managers = [];
4044
managers.push(new Manager(this));
41-
this.employeeLevels[1] = managers;
45+
this.employeeLevels.push(managers);
4246

4347
// Create directors.
44-
let directors = new Array(NUM_DIRECTORS);
48+
let directors = [];
4549
directors.push(new Director(this));
46-
this.employeeLevels[2] = directors;
50+
this.employeeLevels.push(directors);
4751
}
4852

4953
/* Gets the first available employee who can handle this call. */
@@ -75,7 +79,7 @@ export class CallHandler {
7579
} else {
7680
/* Place the call into corresponding call queue according to its rank. */
7781
call.reply("Please wait for free employee to reply");
78-
callQueues[call.getRank().getValue()].push(call);
82+
this.callQueues[call.getRank()].push(call);
7983
}
8084
}
8185

@@ -84,7 +88,7 @@ export class CallHandler {
8488
* if we were able to assign a call, false otherwise. */
8589
assignCall(emp) {
8690
/* Check the queues, starting from the highest rank this employee can serve. */
87-
for (let rank = emp.getRank().getValue(); rank >= 0; rank--) {
91+
for (let rank = emp.getRank(); rank >= 0; rank--) {
8892
let que = this.callQueues[rank];
8993

9094
/* Remove the first call, if any */

src/chapter7/q2/Employee.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export class Employee {
1313
/* Start the conversation */
1414
receiveCall(call) {
1515
this.currentCall = call;
16+
17+
setTimeout(() => this.callCompleted(), 3000);
1618
}
1719

1820
/* the issue is resolved, finish the call */

src/chapter7/q2/ch7-q2.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ import {Caller} from './Caller';
33

44
let callHandler = new CallHandler();
55

6-
let caller = new Caller(1, 'alex');
7-
callHandler.dispatchCall(caller);
6+
for(let i = 0; i < 50; i++){
7+
let caller = new Caller(i, ''+i);
8+
callHandler.dispatchCall(caller);
9+
}

0 commit comments

Comments
 (0)