diff --git a/examples/experimental/csv-parse.js b/examples/experimental/csv-parse.js index 36ece396be6..69dfdfa4bd3 100644 --- a/examples/experimental/csv-parse.js +++ b/examples/experimental/csv-parse.js @@ -7,16 +7,10 @@ export const options = { } // Open the csv file, and parse it ahead of time. -let file; -let csvRecords; -(async function () { - file = await open('data.csv'); - - // The `csv.parse` function consumes the entire file at once, and returns - // the parsed records as a SharedArray object. - csvRecords = await csv.parse(file, {delimiter: ','}) -})(); - +const file = await open('data.csv'); +// The `csv.parse` function consumes the entire file at once, and returns +// the parsed records as a SharedArray object. +const csvRecords = await csv.parse(file, { delimiter: ',' }) export default async function() { // The csvRecords a SharedArray. Each element is a record from the CSV file, represented as an array diff --git a/examples/experimental/csv-parser.js b/examples/experimental/csv-parser.js index d074014da6f..70cb2ca84aa 100644 --- a/examples/experimental/csv-parser.js +++ b/examples/experimental/csv-parser.js @@ -5,12 +5,8 @@ export const options = { iterations: 10, } -let file; -let parser; -(async function () { - file = await open('data.csv'); - parser = new csv.Parser(file); -})(); +const file = await open('data.csv');; +const parser = new csv.Parser(file);; export default async function() { // The parser `next` method attempts to read the next row from the CSV file. @@ -18,7 +14,7 @@ export default async function() { // It returns an iterator-like object with a `done` property that indicates whether // there are more rows to read, and a `value` property that contains the row fields // as an array. - const {done, value} = await parser.next(); + const { done, value } = await parser.next(); if (done) { throw new Error("No more rows to read"); } diff --git a/examples/experimental/fs/fs.js b/examples/experimental/fs/fs.js index 436f94ac543..b661654517d 100644 --- a/examples/experimental/fs/fs.js +++ b/examples/experimental/fs/fs.js @@ -5,16 +5,11 @@ export const options = { iterations: 1000, }; -// k6 doesn't support async in the init context. We use a top-level async function for `await`. -// // Each Virtual User gets its own `file` copy. // So, operations like `seek` or `read` won't impact other VUs. -let file; -(async function () { - file = await open("bonjour.txt"); -})(); +const file = await open("bonjour.txt"); -export default async function () { +export default async function() { // About information about the file const fileinfo = await file.stat(); if (fileinfo.name != "bonjour.txt") {