-
Notifications
You must be signed in to change notification settings - Fork 811
/
Copy pathBootstrapStep.js
51 lines (47 loc) · 1.67 KB
/
BootstrapStep.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class BootstrapStep {
constructor({websocket, texts, actor, request}) {
this.websocket = websocket;
this.texts = texts;
this.actor = actor;
this.request = request;
}
run(timeout) {
return new Promise((resolve, reject) => {
if(this.actor != undefined)
this.actor(this.websocket);
let promise;
switch(this.request.type) {
case "waitForMessage": {
promise = this.websocket.waitForMessage({
condition: this.request.condition,
keepWhenHit: false,
timeout: timeout
});
break;
}
case "call": {
promise = this.websocket.call({
callArgs: this.request.callArgs,
ignoreCondition: this.request.ignoreCondition,
successCondition: this.request.successCondition,
successActor: this.request.successActor,
failureActor: this.request.failureActor,
timeoutCondition: this.request.timeoutCondition,
timeout: timeout
});
break;
}
}
if(promise != undefined) {
return promise.then((...args) => {
resolve(...args);
})
.catch((...args) => {
reject(...args);
});
}
});
}
}
if(typeof window === 'undefined')
exports.BootstrapStep = BootstrapStep;