Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing of optional message to exit and onExit methods #104

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions carol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Application extends EventEmitter implements types.Application {
httpHandler_: types.HttpHandler | null = null;
private readonly pendingWindows_ = new Map<string, PendingWindow>();
private readonly windows_ = new Map<Page, Window>();
private readonly done_ = deferred<void>();
private readonly done_ = deferred<string | void>();

constructor(
private readonly browser: Browser,
Expand Down Expand Up @@ -147,7 +147,7 @@ class Application extends EventEmitter implements types.Application {
return result;
}

async exit(): Promise<void> {
async exit(message?: string): Promise<string | void> {
this.logger_.debug("[app] app.exit...");
if (this.exited_) {
return;
Expand All @@ -161,12 +161,12 @@ class Application extends EventEmitter implements types.Application {
tryClose(this.chromeProcess.stderr);
}
tryClose(this.chromeProcess);
this.done_.resolve();
this.emit(Application.Events.Exit, null);
this.done_.resolve(message);
this.emit(Application.Events.Exit, message);
return this.done_;
}

onExit(): Promise<void> {
onExit(): Promise<string | void> {
return this.done_;
}

Expand Down
19 changes: 19 additions & 0 deletions carol_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,25 @@ test("Application#onExit", async () => {
assert(called);
});

test("Application#onExit - message", async () => {
const app = await launch({
width: 480,
height: 320,
args: ["--headless"],
});
const exitMessage = "my exit message";

let called = false;
app.onExit().then((message) => {
called = true;
assertStrictEquals(message, exitMessage);
});

await app.exit(exitMessage);

assert(called);
});

testApp(
"Application#serveFolder",
async (app) => {
Expand Down
4 changes: 2 additions & 2 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ export interface Application {
/**
* Close the app windows.
*/
exit(): Promise<void>;
exit(message?: string): Promise<string | void>;

/**
* Returns the promise that will be resolved when the app is closed.
*/
onExit(): Promise<void>;
onExit(): Promise<string | void>;

/**
* @return main window.
Expand Down