Skip to main content

Library for using callbacks to resume your code.

Project description

https://github.com/FichteFoll/resumeback/workflows/CI/badge.svg https://coveralls.io/repos/FichteFoll/resumeback/badge.svg https://img.shields.io/pypi/v/resumeback.svg https://img.shields.io/pypi/pyversions/resumeback.svg

A Python library for using callbacks to resume your code.

resumeback provides a utility function decorator that enables using callback-based interfaces in a single line of execution – a single function.

Documentation

https://fichtefoll.github.io/resumeback/

Installation

$ pip install resumeback

Example Usage

from threading import Thread
from resumeback import send_self

def ask_for_user_input(question, on_done):
    def watcher():
        result = input(question)
        on_done(result)

    Thread(target=watcher).start()

@send_self
def main(this):  # "this" is a reference to the created generator instance
    arbitrary_value = 10

    # Yield pauses execution until one of the generator methods is called,
    # such as `.send`, which we provide as the callback parameter.
    number = yield ask_for_user_input("Please enter a number", this.send)
    number = int(number)
    print("Result:", number * arbitrary_value)

if __name__ == "__main__":
    main()

Development

Requires Python, poetry, and GNU Make.

Use make help to show the available targets.

  • poetry is used for dependency and virtualenv management.

  • tox is used as a test runner for multiple isolated environments.

  • flake8 is used for code linting.

  • Github Actions are used for CI.

Acknowledgements

Project started initially after a forum post from @Varriount on the Sublime Text forum. I just took his idea “to the next (abstraction) level” and made it more convenient to use.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

resumeback-1.0.0.tar.gz (11.5 kB view hashes)

Uploaded Source

Built Distribution

resumeback-1.0.0-py3-none-any.whl (6.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page