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

chore: update examples to use TLA #4040

Merged
merged 1 commit into from
Nov 7, 2024
Merged
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
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