Skip to content

Commit

Permalink
Ajustar mensagem de interrupção
Browse files Browse the repository at this point in the history
  • Loading branch information
dgadelha committed Jan 6, 2025
1 parent 2cdbe0d commit edc60e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
17 changes: 8 additions & 9 deletions packages/runner/src/PortugolExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ export class PortugolExecutor {
next: event => {
switch (event.type) {
case "finish": {
this.stdOut += `\nPrograma finalizado. Tempo de execução: ${event.time} milissegundos\n`;
if (event.stopped) {
this.stdOut += `\nO programa foi interrompido! Tempo de execução: ${event.time} milissegundos\n`;
} else {
this.stdOut += `\nPrograma finalizado. Tempo de execução: ${event.time} milissegundos\n`;
}

this.#printTimes({ ...times, execution: event.time });
this.stdOut$.next(this.stdOut);
break;
Expand All @@ -186,12 +191,6 @@ export class PortugolExecutor {
break;
}

/*case "message": {
this.stdOut += `\nℹ️ ${JSON.stringify(event.message)}\n`;
this.stdOut$.next(this.stdOut);
break;
}*/

default: {
break;
}
Expand All @@ -217,7 +216,7 @@ export class PortugolExecutor {
}

stop() {
this.reset();
this.reset(false);
}

private reset(clearStdOut = true) {
Expand All @@ -233,7 +232,7 @@ export class PortugolExecutor {
this.running = false;
this._running$?.unsubscribe();

this._runner?.destroy();
this._runner?.destroy(true);
}

postMessage(message: PortugolMessage) {
Expand Down
4 changes: 2 additions & 2 deletions packages/runner/src/runners/IPortugolRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type PortugolEvent =
| { type: "stdIn" }
| { type: "error"; error: Error }
| { type: "parseError"; errors: PortugolCodeError[] }
| { type: "finish"; time: number }
| { type: "finish"; stopped: boolean; time: number }
| { type: "message"; message: PortugolMessage };

export type PortugolMessage = {
Expand All @@ -29,7 +29,7 @@ export abstract class IPortugolRunner {
abstract running$: Observable<boolean>;

abstract run(): Observable<PortugolEvent>;
abstract destroy(): void;
abstract destroy(stopped?: boolean): void;

abstract postMessage(message: PortugolMessage): void;
abstract replyMessage(message: PortugolMessage, result: unknown, transferable?: Transferable[]): void;
Expand Down
3 changes: 2 additions & 1 deletion packages/runner/src/runners/PortugolWebWorkersRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,13 @@ export class PortugolWebWorkersRunner extends IPortugolRunner {
return this._run;
}

destroy() {
destroy(stopped = false) {
this.worker.terminate();

this._run.next({
type: "finish",
time: Date.now() - (this.startedAt?.getTime() ?? 0),
stopped,
});

this._run.complete();
Expand Down

0 comments on commit edc60e6

Please sign in to comment.