0

I am using deasync module to make functions synchronized in Node.js. But program takes more time to finish. However data is returned quickly to console.

var storeintodrive = function moveFileTo (filename){
    var hash;
    var sync = true

    //do some operation
    hash = XXXXXXXXXXXXX
    sync = false;

    while (sync) {
        require('deasync').sleep(10);
    }
    return hash;
}

var hexifydata = function(array,filedata){

    var sync = true;

    // do some opration
    Records.push(record[0]);                        
    sync = false;

    while (sync) {
        require('deasync').sleep(10);
    }       
    return Records;
}

Due to late in response from these functions,frond end JS is not getting correct response from NodeJs. Please suggest me how do I get response faster from both functions.

Sergey
  • 7,985
  • 4
  • 48
  • 80
  • 1
    *I am using deasync module to make functions synchronized in Node.js.* Why? Seems like a really bad idea. – Ry- Nov 23 '16 at 08:42
  • @Ryan I need some data to be returned from these functions and use for next processing. O/P of function1 is an input to function2.What should be solution in such scenario.I am not expert in Node.js.This is how I have been working in Perl/Python. – user2536239 Nov 23 '16 at 08:46
  • You can't write node.js like you write Perl/Python. Instead, you have to learn how to program for async results in node.js. It's a really, really bad idea to try to turn async into synchronous. – jfriend00 Nov 23 '16 at 08:50
  • @jfriend00 Ok. Is there any good material available on net which I can learn quickly? – user2536239 Nov 23 '16 at 09:00
  • You can read this: [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – jfriend00 Nov 23 '16 at 09:03
  • @jfriend00 Thanks a lot – user2536239 Nov 23 '16 at 09:19

0 Answers0