1

I have the bellow function

const generate_data = require('./helpers/generate_train_data');
const permutate_data = require('./helpers/permutate_data');

var COMPANY = 'test-company';
var INVOICES = ['invoice2.pdf','invoice4.pdf','invoice5.pdf'];

generate_data.generate_data(COMPANY, INVOICES,(check)=>{
    if(check){
        console.log('Success, training data created!');
    }
    else{
        //Call generate_data.generate_date again with SAME INPUT 
    }
});

Basically i am waiting for a return falue of the generate_date module, and if that value if true i just just a simple printout, but if that value is false i need to call again the same function

generate_data.generate_data(COMPANY, INVOICES, (AND HERE THE SAME CALLBACK...)

I tried using generate_data.generate_data.call(arguments.callee.caller), but i get undefined value fo the arguments.callee.caller..

1 Answer 1

1

You can achive this by storing callback in separate function, so you reference it inside

const customCallback = (check) => {
    if (check) {
        console.log('Success, training data created!');
    } else {
        //Call generate_data.generate_date again with SAME INPUT 
        generate_data.generate_data(COMPANY, INVOICES, customCallback);
    }
}

generate_data.generate_data(COMPANY, INVOICES, customCallback);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, didn't even think about separating it, it troubled me badly today... Cheers.
@KristijanStefanoski Glad to help. Also do not forget to mark an answer as correct if it solved your probem)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.