Skip to content

Commit a40d853

Browse files
committed
chore: update examples to use TLA
1 parent 8dfdef1 commit a40d853

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

examples/experimental/csv-parse.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,10 @@ export const options = {
77
}
88

99
// Open the csv file, and parse it ahead of time.
10-
let file;
11-
let csvRecords;
12-
(async function () {
13-
file = await open('data.csv');
14-
15-
// The `csv.parse` function consumes the entire file at once, and returns
16-
// the parsed records as a SharedArray object.
17-
csvRecords = await csv.parse(file, {delimiter: ','})
18-
})();
19-
10+
const file = await open('data.csv');
11+
// The `csv.parse` function consumes the entire file at once, and returns
12+
// the parsed records as a SharedArray object.
13+
const csvRecords = await csv.parse(file, { delimiter: ',' })
2014

2115
export default async function() {
2216
// The csvRecords a SharedArray. Each element is a record from the CSV file, represented as an array

examples/experimental/csv-parser.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@ export const options = {
55
iterations: 10,
66
}
77

8-
let file;
9-
let parser;
10-
(async function () {
11-
file = await open('data.csv');
12-
parser = new csv.Parser(file);
13-
})();
8+
const file = await open('data.csv');;
9+
const parser = new csv.Parser(file);;
1410

1511
export default async function() {
1612
// The parser `next` method attempts to read the next row from the CSV file.
1713
//
1814
// It returns an iterator-like object with a `done` property that indicates whether
1915
// there are more rows to read, and a `value` property that contains the row fields
2016
// as an array.
21-
const {done, value} = await parser.next();
17+
const { done, value } = await parser.next();
2218
if (done) {
2319
throw new Error("No more rows to read");
2420
}

examples/experimental/fs/fs.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ export const options = {
55
iterations: 1000,
66
};
77

8-
// k6 doesn't support async in the init context. We use a top-level async function for `await`.
9-
//
108
// Each Virtual User gets its own `file` copy.
119
// So, operations like `seek` or `read` won't impact other VUs.
12-
let file;
13-
(async function () {
14-
file = await open("bonjour.txt");
15-
})();
10+
const file = await open("bonjour.txt");
1611

17-
export default async function () {
12+
export default async function() {
1813
// About information about the file
1914
const fileinfo = await file.stat();
2015
if (fileinfo.name != "bonjour.txt") {

0 commit comments

Comments
 (0)