-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
81 lines (75 loc) · 2 KB
/
index.mjs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const sleep = (secs) => {
const start = Date.now();
while (Date.now() - start < secs * 1000) {}
};
export const buildRocket = () => {
console.log('Building rocket...');
sleep(5);
console.log('Rocket built!');
const rocket = {
altitude: 0,
speed: 0,
engines: [{ isFiring: false }, { isFiring: false }],
addCrew: (crew) => {
console.log('Adding crew...');
sleep(0.5);
console.log('Crew ready!');
},
addFuel: (fuel) => {
console.log('Adding fuel...');
sleep(0.5);
console.log('Fuel ready!');
},
fireEngine: (num) => {
if (!rocket.engines[num].isFiring) {
console.log(`Firing engine ${num}...`);
rocket.engines[num].isFiring = true;
}
sleep(0.01);
rocket.altitude += 10;
rocket.speed += 700;
console.log(`Altitude ${rocket.altitude}km | Speed ${rocket.speed}km/h`);
},
stopEngine: (num) => {
console.log(`Engine ${num} cut-off...`);
sleep(0.5);
rocket.engines[num].isFiring = false;
console.log(`Engine ${num} cut-off completed...`);
},
engineIsFiring: num => rocket.engines[num].isFiring,
runStageSeparation: (num) => {
console.log(`Running stage ${num} separation...`);
sleep(1);
console.log(`Stage ${num} separation completed...`);
},
};
return rocket;
};
export const fetchCrew = () => {
console.log('Fetching crew...');
sleep(3);
console.log('Crew ready!');
return [
{ name: 'Pepito Pérez' },
{ name: 'Manolita Fernández' },
];
};
export const getFuel = () => {
console.log('Getting fuel...');
sleep(1);
console.log('Fuel ready!');
return {};
};
export const bookLaunchPad = () => {
console.log('Booking launch pad...');
sleep(5);
console.log('Launch pad booked!');
return {
addRocket: (rocket) => {
console.log('Adding rocket to launch pad...');
sleep(2);
console.log('Added rocket to launch pad!');
},
};
};
export default { buildRocket, fetchCrew, getFuel, bookLaunchPad };