1

I am using cordova barcode scanner and there is a sample like this.
Despite the comment there, I am unsure of why exactly does the setTimeout is necessary here.
What does it mean by so the dialog does not free the app?

cordova.plugins.barcodeScanner.scan(

    // success callback function
    function (result) {
        // wrapping in a timeout so the dialog doesn't free the app
        setTimeout(function() {
            alert("We got a barcode\n" +
                  "Result: " + result.text + "\n" +
                  "Format: " + result.format + "\n" +
                  "Cancelled: " + result.cancelled);                            
        }, 0);
    },

    // error callback function
    function (error) {
        alert("Scanning failed: " + error);
    },

    // options object
    {
        ...
    }
desmondlee
  • 1,643
  • 4
  • 21
  • 33
  • http://stackoverflow.com/questions/36108158/why-would-i-wrap-a-function-in-angularjs-timeout-service-without-a-delay-like-t – Marko Feb 14 '17 at 21:16

1 Answers1

0

alert, confirm and prompt are not part of regular javascript, these APIs are provided by browser vendors, and synchronous in nature. whenever alert, confirm and prompt are being called the Javascript thread blocks and wait for user to interact with these, in that moment whole VM(javascript execution thread) blocked and do nothing.

Ajay Singh
  • 62
  • 5