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

"ReferenceError: list is not defined": The outside variable cannot be used/recognized during mapping. #228

Open
zhengger opened this issue Aug 30, 2021 · 2 comments

Comments

@zhengger
Copy link

zhengger commented Aug 30, 2021

I want to push value to variable list during mapping. It ends in the error "ReferenceError: list is not defined".
I'm using typescript and below is my code.

import Parallel from 'paralleljs';
import { performance } from "perf_hooks";
import * as _ from "lodash";

const l = _.range(10,20);
const p = new Parallel(l);

const log = function () { console.log(arguments); };
const current_encode_Time_before = performance.now();
// One gotcha: anonymous functions cannot be serialzed
// If you want to do recursion, make sure the function
// is named appropriately

const list: Array<number> = [];  // I want to push new value to list during mapping 

function fib(n: number): number{
    let num: number = 0;
    num = n < 2 ? 1 : fib(n - 1) + fib(n - 2);
    list.push(num);
    return num;
};

p.map(fib).then(() => {
    const current_encode_Time_later = performance.now();
    console.log(
        "Parra: Test_Time difference",
        (current_encode_Time_later - current_encode_Time_before) / 1000
    );
});

The error is:

ReferenceError: list is not defined
    at fib (eval at <anonymous> (/Users/zhen/dev/simple/node_modules/_paralleljs@1.1.0@paralleljs/lib/eval.js:7:5), <anonymous>:4:5)

Thanks a lot!

@far11ven
Copy link

@zhengger did you resolve this?

@zhengger
Copy link
Author

@zhengger did you resolve this?

Not yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants