Skip to content

Commit

Permalink
chore: update examples to use TLA
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Nov 7, 2024
1 parent 8dfdef1 commit a40d853
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
14 changes: 4 additions & 10 deletions examples/experimental/csv-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions examples/experimental/csv-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ 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.
//
// 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");
}
Expand Down
9 changes: 2 additions & 7 deletions examples/experimental/fs/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit a40d853

Please sign in to comment.