Giter Site home page Giter Site logo

python-call's Introduction

Call

https://api.codacy.com/project/badge/Grade/91959f98ff34469884415e96ba2ff763:target:https://www.codacy.com/app/solarliner/call?utm_source=gitlab.com&utm_medium=referral&utm_content=solarliner/call&utm_campaign=Badge_Grade

Thread-based, JS-like asynchronous calls for Python. Works in both Python 2.7 and Python 3.5+.

Install

Release version:

Development version

git clone https://gitlab.com/solarliner/call.git
cd call
# Activate virtualenv if needed
python setup.py install

The library requires no other dependencies, and (will soon) support Python's await keyword.

Use

Create a call:

def cb(resolve, reject):
    result = factorial(100)
    resolve(result)

call = Call(cb)

Wrap a synchronous function in a Call:

Chain calls with the then keyword

call = Call(cb).then(lambda val: print(val))

Catch errors:

call = Call(cb)\
    .then(lambda val: raise Exception())\
    .catch(lambda err: print('Whoops'))

Compose calls:

results = Call.all([Call(cb) for _ in range(10)])

Block thread until resolved (or raises on failure):

result = call.wait()

Wait for call to either resolve or reject. Note that it is not recommended to get the data directly, as it may be None, which may or may not indicate that an error has occurred.

call.join()
result = call.data  # Not recommended

Contribute

The repository follows the git flow standards. Create a feature branch, then ask for a pull/merge request.

The main repository is on GitLab, however the GitHub mirror is functional and you should be able to ask for pull requests. However, they will be processed in GitLab.

python-call's People

Contributors

solarliner avatar

Stargazers

Juwan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.