Skip to content

Invoking a coroutine with a custom continuation #121

@Simn

Description

@Simn

I have a case in #119 where I'm in a coroutine and want to call another coroutine, but with a different continuation. So something like this:

import haxe.coro.CoroIntrinsics;
import hxcoro.Coro.*;
import hxcoro.CoroRun;
import hxcoro.concurrent.CoroLatch;
import hxcoro.continuations.FunctionContinuation;

function main() {

	@:coroutine function g() {
		trace("g()");
		yield();
	}

	@:coroutine function f() {
		trace("f()");

		final latch = new CoroLatch(1);
		final myCont = new FunctionContinuation(CoroIntrinsics.getContext(), (_, _) -> {
			trace("Called!");
			latch.arrive(1);
		});

		// workaround
		(() -> g(myCont))();

		latch.wait();
	}
	CoroRun.run(f);
}

This works, but I wonder if there should be a more obvious way of doing this.

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