Skip to content

How to use these for non-local jumps? #1

@trenta3

Description

@trenta3

I'm trying to use this continuation library but I cannot figure out how to call a saved continuation.
Please consider the below example which should implement an infinite while cycle.
How would I go to implement the restorecc function?

Thank you in advance.

from continuation import with_CC, with_continuation

saved = None

@with_continuation
def savecc(k):
    def _inner():
        print("Saving CC")
        global saved
        saved = k
    return _inner

@with_continuation
def nothing(k):
    def _inner():
        pass
    return _inner

def restorecc():
    print("Restoring CC")
    global saved
    (saved << nothing)()

def cycle():
    print("We are at the start")
    i = 0
    (with_CC >> savecc)()
    i = i + 1
    print(f"I: {i}")
    restorecc()

cycle()

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