Skip to content

Commit a3ea001

Browse files
committed
useActive in executor
1 parent 1fbf2d8 commit a3ea001

File tree

1 file changed

+53
-46
lines changed

1 file changed

+53
-46
lines changed

src/vm/executor.service.ts

+53-46
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { EventEmitter, Injectable, Output } from '@angular/core';
33
import { CommandQueueService } from './commandQueue.service';
44
import { EmulatorService } from './emulator.service';
55
import { once } from '../utils/misc';
6+
import { ByondService } from './byond.service';
67

78
@Injectable({
89
providedIn: 'root',
@@ -16,60 +17,66 @@ export class ExecutorService {
1617
constructor(
1718
private commandQueue: CommandQueueService,
1819
private emulator: EmulatorService,
20+
private byondService: ByondService,
1921
) {}
2022

2123
public async executeImmediate(
2224
code: string,
2325
signal?: AbortSignal,
2426
): Promise<void> {
25-
const filename = `tmp-${Date.now()}`;
26-
let stageAbort: Function | undefined = undefined;
27+
return this.byondService.useActive((path) => {
28+
if (path == null)
29+
return Promise.reject(new Error('No active byond version'));
2730

28-
this.reset.emit();
29-
const promise = new CancelablePromise<void>((resolve) => {
30-
resolve(this.emulator.start());
31-
})
32-
.then(() => {
33-
return this.emulator.sendFile(filename + '.dme', code);
34-
})
35-
.then(() => {
36-
return this.commandQueue.runProcess(
37-
'/byond/bin/DreamMaker',
38-
'/mnt/host/' + filename + '.dme',
39-
new Map([['LD_LIBRARY_PATH', '/byond/bin']]),
40-
);
41-
})
42-
.then((compiler) => {
43-
this.output.emit('=== Compile stage ===\n');
44-
compiler.stdout.subscribe((val) => this.output.emit(val));
45-
stageAbort = compiler.kill;
46-
return once(compiler.exit);
47-
})
48-
.then(() => {
49-
return this.commandQueue.runProcess(
50-
'/byond/bin/DreamDaemon',
51-
`/mnt/host/${filename}.dmb\0-trusted`,
52-
new Map([['LD_LIBRARY_PATH', '/byond/bin']]),
53-
);
54-
})
55-
.then((server) => {
56-
this.output.emit('\n=== Run stage ===\n');
57-
server.stderr.subscribe((val) => this.output.emit(val));
58-
stageAbort = server.kill;
59-
return once(server.exit);
60-
})
61-
.then(() => {
62-
stageAbort = undefined;
31+
const filename = `tmp-${Date.now()}`;
32+
let stageAbort: Function | undefined = undefined;
33+
34+
this.reset.emit();
35+
const promise = new CancelablePromise<void>((resolve) => {
36+
resolve(this.emulator.start());
6337
})
64-
.finally(() => {
65-
if (stageAbort) stageAbort();
66-
this.commandQueue.runProcess(
67-
'/bin/rm',
68-
`/mnt/host/${filename}.dme\0/mnt/host/${filename}.dmb`,
69-
);
70-
}, true);
38+
.then(() => {
39+
return this.emulator.sendFile(filename + '.dme', code);
40+
})
41+
.then(() => {
42+
return this.commandQueue.runProcess(
43+
path + 'DreamMaker',
44+
'/mnt/host/' + filename + '.dme',
45+
new Map([['LD_LIBRARY_PATH', path]]),
46+
);
47+
})
48+
.then((compiler) => {
49+
this.output.emit('=== Compile stage ===\n');
50+
compiler.stdout.subscribe((val) => this.output.emit(val));
51+
stageAbort = compiler.kill;
52+
return once(compiler.exit);
53+
})
54+
.then(() => {
55+
return this.commandQueue.runProcess(
56+
path + 'DreamDaemon',
57+
`/mnt/host/${filename}.dmb\0-trusted`,
58+
new Map([['LD_LIBRARY_PATH', path]]),
59+
);
60+
})
61+
.then((server) => {
62+
this.output.emit('\n=== Run stage ===\n');
63+
server.stderr.subscribe((val) => this.output.emit(val));
64+
stageAbort = server.kill;
65+
return once(server.exit);
66+
})
67+
.then(() => {
68+
stageAbort = undefined;
69+
})
70+
.finally(() => {
71+
if (stageAbort) stageAbort();
72+
this.commandQueue.runProcess(
73+
'/bin/rm',
74+
`/mnt/host/${filename}.dme\0/mnt/host/${filename}.dmb`,
75+
);
76+
}, true);
7177

72-
signal?.addEventListener('abort', () => promise.cancel());
73-
return promise;
78+
signal?.addEventListener('abort', () => promise.cancel());
79+
return promise;
80+
});
7481
}
7582
}

0 commit comments

Comments
 (0)