Skip to content

Commit fb93322

Browse files
committed
use promises in complexity plugin
1 parent a66fb67 commit fb93322

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

examples/complexity.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@ class Complexity<PostType> implements instamancer.IPlugin<PostType> {
88
this.query = query;
99
}
1010

11-
public responseEvent(
11+
public async responseEvent(
1212
this: instamancer.IPluginContext<Complexity<PostType>, PostType>,
1313
res: Response,
1414
data: {[key: string]: any},
15-
): void {
16-
this.state.page
17-
.evaluate((query) => {
18-
return document.querySelectorAll(query).length;
19-
}, this.plugin.query)
20-
.then((count) => {
21-
process.stdout.write(
22-
`${this.plugin.query} elements: ${count}\n`,
23-
);
24-
});
15+
): Promise<void> {
16+
const elementCount = await this.state.page.evaluate((query) => {
17+
return document.querySelectorAll(query).length;
18+
}, this.plugin.query);
19+
process.stdout.write(
20+
`${this.plugin.query} elements: ${elementCount}\n`,
21+
);
2522
}
2623
}
2724

0 commit comments

Comments
 (0)