Skip to main content

Bind functions to run only once inside a desired scope.

Project description

PyPI PyPI - Python Version GitHub https://travis-ci.org/jsfehler/stere.svg?branch=master

Bind functions to only run once inside a desired scope.

Documentation

The Rig class exposes two methods: bind and free. Bind takes one argument: A name for a scope to bind the function.

Functions wrapped with bind will be called only once until the scope it is inside is freed.

Functions wrapped with free will free all the bound functions in a specific scope after the function’s execution.

Example:

import shibari


rig = shibari.Rig('ebi')


@rig.bind('ebi')
def timestamp():
    return str(time.time())


@rig.free('ebi')
def finish():
    pass


>>> t = timestamp()
>>> t2 = timestamp()
>>> assert t == t2

>>> finish()

>>> t3 = timestamp()
>>> t4 == timestamp()
>>> assert t != t3
>>> assert t3 == t4

Functions that take arguments can be bound, but will always return the same result until they are freed.

Example:

import shibari


rig = shibari.Rig('ebi')


@rig.bind('ebi')
def timestamp(a, b):
    return f'{a}_{str(time.time())}_{b}'


>>> t = timestamp('goodbye', 'world')
>>> t2 = timestamp('hello', 'space')
>>> assert t == t2

Project details


Download files

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

Files for shibari, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size shibari-0.0.2-py3-none-any.whl (4.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size shibari-0.0.2.tar.gz (2.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page