MarkLogic Qconsole Javascript code output

Viewed 63

The following code:

function* logGenerator() {
 console.log(0);
 console.log(1, yield);
 console.log(2, yield); 
 console.log(3, yield);
} 
 var gen = logGenerator(); 
// the first call of next executes from the start of the function 
// until the first yield statement
 gen.next();             // 0
 gen.next('pretzel');    // 1 pretzel
 gen.next('california'); // 2 california
 gen.next('mayonnaise'); // 3 mayonnaise

I have taken this code from the following site in the Passing arguments into Generators section. I am trying to produce this code in the MarkLogic Qconsole Javascipt Site

The output that I get for the first three items is

"done": false
"done": false
"done": false
"done": true
//instead of the expected output 
gen.next();             // 0
gen.next('pretzel');    // 1 pretzel
gen.next('california'); // 2 california
gen.next('mayonnaise'); // 3 mayonnaise

Does anyone have any ideas why this behavior or is there anything different I must do?

1 Answers

Why:

The console.log you use is the JavaScript Web API which outputs the text to a console. MarkLogic console.log outputs the text to server log file. If you check your MarkLogic log file {MarkLogic-root-directory}/{port-number}_ErrorLog, you should see:

{timestamp} Info: 0
{timestamp} Info: 1 pretzel
{timestamp} Info: 2 california
{timestamp} Info: 3 mayonnaise

To output the result to the MarkLogic Query Console, please serialise and then iterate the parameters:

function* logGenerator(arr) {
  for (var chain of arr) {
    yield chain;
  }
}
let arrObj = ['0', '1 pretzel', '2 california', '3 mayonnaise']
const result = []
for(const chain of logGenerator(arrObj)) {
  result.push(chain);
}
result;
Related