Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async function error: TypeError: Generator is already running #9372

Closed
phiresky opened this issue Jun 27, 2016 · 7 comments
Closed

async function error: TypeError: Generator is already running #9372

phiresky opened this issue Jun 27, 2016 · 7 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@phiresky
Copy link

phiresky commented Jun 27, 2016

TypeScript Version: Version 1.8.10 and Version 1.9.0-dev.20160626-1.0

Chromium Version: Version 51.0.2704.103 (64-bit)

Code

"use strict";

function count(): number {
    return 42;
}
async function countAsync(): Promise<number> {
    return count();
}
countAsync()

html:

<script src="bin/main.js"></script>

Expected behavior: print 42

Actual behavior:

main.ts:2 Uncaught (in promise) TypeError: Generator is already running
    at next (native)
    at fulfilled (http://localhost:8000/bin/main.js:4:58)

Emitted Javascript (ES6):

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments)).next());
    });
};
function count() {
    return 42;
}
function countAsync() {
    return __awaiter(this, void 0, Promise, function* () {
        return count();
    });
}
countAsync().then(x => console.log(x));
//# sourceMappingURL=main.js.map

Same code works fine in node v6.2.2

@anjmao
Copy link

anjmao commented Jun 27, 2016

Tried your code. It works fine for me on Chrome: 51.0.2704.106 v :)

@phiresky
Copy link
Author

phiresky commented Jun 27, 2016

Same issue appears here: https://phiresky.github.io/qalc-react/ for me, which worked some time ago.

@Arnavion
Copy link
Contributor

Arnavion commented Jun 27, 2016

This is a Chrome (edit: that is, V8) bug (testing on dev version v53).

"use strict";

function count() { return 42; }
var generator = function* () { return count(); }
var g = generator.apply(undefined, undefined);
console.log(g.next());

incorrectly logs 42.

Inlining the result of count()

"use strict";

function count() { return 42; }
var generator = function* () { return 42; }
var g = generator.apply(undefined, undefined);
console.log(g.next());

correctly logs Object {value: 42, done: true}

The former is the bug. In the original emit, step gets a bad value 42 because of it.

@RyanCavanaugh RyanCavanaugh added the External Relates to another program, environment, or user action which we cannot control. label Jun 27, 2016
@RyanCavanaugh
Copy link
Member

Please log this in the V8 issue tracker. We don't have any way to account for broken runtimes.

@phiresky
Copy link
Author

Okay, I apparently had the enable-javascript-harmony flag enabled in chrome://flags . Disabling that solves this problem for chrome stable.

@Jessidhia
Copy link

Is there a tracking bug for this? This is now affecting Canary, even without the harmony flag.

@Arnavion
Copy link
Contributor

I didn't find an existing bug, so I've created https://bugs.chromium.org/p/v8/issues/detail?id=5322

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

5 participants