Skip to content

Commit

Permalink
Modify csv module's documentation to reflect top-level await support
Browse files Browse the repository at this point in the history
  • Loading branch information
oleiade committed Nov 5, 2024
1 parent b77046a commit c394095
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 39 deletions.
18 changes: 7 additions & 11 deletions docs/sources/k6/next/javascript-api/k6-experimental/csv/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@ The `Options` object describes the configuration available for the operation of
import { open } from 'k6/experimental/fs';
import csv from 'k6/experimental/csv';

let file;
let parser;
(async function () {
file = await open('data.csv');
parser = new csv.Parser(file, {
delimiter: ',',
skipFirstLine: true,
fromLine: 2,
toLine: 8,
});
})();
const file = await open('data.csv');
const parser = new csv.Parser(file, {
delimiter: ',',
skipFirstLine: true,
fromLine: 2,
toLine: 8,
});

export default async function () {
// The `next` method attempts to read the next row from the CSV file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,8 @@ export const options = {
iterations: 10,
};

let file;
let parser;
(async function () {
file = await open('data.csv');
parser = new csv.Parser(file, { skipFirstLine: true });
})();
const file = await open('data.csv');
const parser = new csv.Parser(file, { skipFirstLine: true });

export default async function () {
// The `next` method attempts to read the next row from the CSV file.
Expand Down
23 changes: 9 additions & 14 deletions docs/sources/k6/next/javascript-api/k6-experimental/csv/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ export const options = {
iterations: 10,
};

let file;
let csvRecords;
(async function () {
file = await open('data.csv');
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.
csvRecords = await csv.parse(file, { delimiter: ',' });
})();
// 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 () {
// `csvRecords` is a `SharedArray`. Each element is a record from the CSV file, represented as an array
Expand All @@ -85,12 +81,11 @@ 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');

// The `csv.parse` function consumes the entire file at once and returns
// the parsed records as a `SharedArray` object.
const parser = new csv.Parser(file);

export default async function () {
// The parser `next` method attempts to read the next row from the CSV file.
Expand Down
12 changes: 4 additions & 8 deletions docs/sources/k6/next/javascript-api/k6-experimental/csv/parse.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,11 @@ export const options = {
iterations: 10,
};

let file;
let csvRecords;
(async function () {
file = await open('data.csv');
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.
csvRecords = await csv.parse(file, { skipFirstLine: true });
})();
// 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, { skipFirstLine: true });

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

0 comments on commit c394095

Please sign in to comment.