Skip to content

Capturing node variables #114

Description

@Simn

Our approach makes it quite easy to mess up the structure of our structured concurrency:

import hxcoro.CoroRun;

function main() {
	CoroRun.runScoped(node -> {
		node.async(_ -> {
			node.async(_ -> trace("uhm"));
		});
	});
}

This is clearly supposed to create a child scope, but because we used _ instead of node for some reason we end up with a sibling scope instead.

I think this would require the notion of variables that cannot be captured. This is easy enough to implement in the compiler, the only question is how it should be communicated from user code. We don't want any additional syntax in the node -> part, so the only solution would be to have some kind of tag on the type of the variable or argument. Maybe something like @:noCapture interface ICoroNode would work.

Although now that I'm writing this, I realize that this wouldn't actually work because we're hoisting the variable. Hmm...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions