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

Return not handled properly? #135

@IngwiePhoenix

Description

@IngwiePhoenix

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions