You are reading a single comment by @Drarok and its replies. Click here to read the full conversation.
  • Interesting! You're right that wrapping into a function works, thanks!

    This works:

    function go() {
      var p1 = new Promise(function (res, rej) {
        setTimeout(() => res(1), 250);
      });
    
      var p2 = new Promise(function (res, rej) {
        setTimeout(() => res(2), 300);
      });
    
      Promise.all([p1, p2]).then(function () {
        console.log('done', arguments);
      }).catch(function () {
        console.log('FAIL');
      });
    
      console.log('Promise test');
    }
    
    go();
    

    Output:

    Promise test
    =undefined
    done [
      [ 1, 2 ]
     ]
    

    But attempting to use ES6 arrow functions as the Promise executor causes the Puck to completely stop responding and require a powercycle before I can interact with it?

    function go() {
    var p1 = new Promise((res, rej) => {
        setTimeout(() => res(1), 250);
      });
    
      var p2 = new Promise((res, rej) => {
        setTimeout(() => res(2), 300);
      });
    
      Promise.all([p1, p2]).then(function () {
        console.log('done', arguments);
      }).catch(function () {
        console.log('FAIL');
      });
    
      console.log('Promise test');
    }
    
    go();
    

    There's no output after the Espruino logo and version text, the console on the left stops working (can't type any text), and attempting to upload code seems to work, but doesn't execute.
    I can disconnect and attempt to reconnect via BLE, which hangs at "Connecting..." – super weird!

About

Avatar for Drarok @Drarok started