Skip to content
This repository has been archived by the owner on Jun 10, 2019. It is now read-only.

Return not handled properly? #135

Open
IngwiePhoenix opened this issue Nov 30, 2018 · 0 comments
Open

Return not handled properly? #135

IngwiePhoenix opened this issue Nov 30, 2018 · 0 comments

Comments

@IngwiePhoenix
Copy link

I have tried something out, and appearently a return value is not passed correctly.

Code:

async function someFunction() {
  return 1;
}

class Foo {
  async init() {
    try {
      var a = await someFunction();
      var b = await someFunction();
      var c = a+b;
      console.log("Math:" + (a+b))
      return c;
    } catch(e) {
      throw e;
    }
  }
}

(async ()=>{
  var e = new Foo()
  var f = await e.init()
  console.log("Res: "+f)
  return 0;
})();

Result:

"use strict";

function someFunction() {
  return Promise.resolve().then(function () {
    return 1;
  });
}

class Foo {
  init() {
    var a, b, c;
    return Promise.resolve().then(function () {
      return Promise.resolve().then(function () {
        return someFunction();
      }).then(function (_resp) {
        a = _resp;
        return someFunction();
      }).then(function (_resp) {
        b = _resp;
        c = a + b;
        console.log("Math:" + (a + b));
        return c;
      }).catch(function (e) {
        throw e;
      });
    }).then(function () {});
  }

}

(() => {
  var e, f;
  return Promise.resolve().then(function () {
    e = new Foo();
    return e.init();
  }).then(function (_resp) {
    f = _resp;
    console.log("Res: " + f);
    return 0;
  });
})();

What that outputs:

Math:2
Res: undefined

Expected:

Math:2
Res: 2 <--

Did I do something wrong in the code? I am not sure about it, so I thought I'd post it here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant