Skulpt - Promise not correctly returning when resolving

234 Views Asked by At

I am trying to get the standard input from a textarea, and I am close to finding the solution but I have found that my promise is not correctly returning a value.

 function sInput() {
      return new Promise(function(resolve,reject){
         $("#outputField").on("keyup", function(e){
             if (e.keyCode == 13){
                console.log("test");
                resolve("5")
                resolve("random test");
             }
         })
      })
   }

The code above is what I have so far (Which does not return "5" or "random test"), but if I change the function to

 function sInput() {
        return "5"
   }

Then "5" is correctly returned. Why is my promise not returning the value correctly? This is a continuation from This example for more exact information

More code :

function runit() { 
   var prog = document.getElementById("inputField").value; 
   var mypre = document.getElementById("outputField"); 
   mypre.innerHTML = ''; 
   Sk.python3 = true;
   Sk.pre = "outputField";

   Sk.configure({ output:outf, 
                  read:builtinRead,
                  inputfun: sInput,
                  inputfunTakesPrompt: true});



   var myPromise = Sk.misceval.asyncToPromise(function() {
       return Sk.importMainWithBody("<stdin>", false, prog, true);
   });

   myPromise.then(function(mod) {
       console.log('success');
   },
       function(err) {
       console.log(err.toString());
   });
} 
0

There are 0 best solutions below