Skip to main content

Thread-based, JS-like asynchronous calls for Python.

Project description

Call
====

.. image:: 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:

.. code:: bash
pip install call

Development version

.. code:: bash

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:

.. code:: python

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

call = Call(cb)

Wrap a synchronous function in a Call:

.. code:: python
call = Call.from_function(factorial, 10)

Chain calls with the ``then`` keyword

.. code:: python

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

Catch errors:

.. code:: python

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

Compose calls:

.. code:: python

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

Block thread until resolved (or raises on failure):

.. code:: python

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.

.. code:: python

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.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

async_call-0.1.2-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

async_call-0.1.2-py2-none-any.whl (3.8 kB view details)

Uploaded Python 2

File details

Details for the file async_call-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: async_call-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for async_call-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9f85e69e0b3052240e9156376a33a18c8736522c1a5118d5434302b48fa9cd87
MD5 bb2e1a82db294493324c5d58a04223a6
BLAKE2b-256 4fef9b273f084a36e8e4fef938cf7af41293dca4c8e56e912cbeb678c90a953d

See more details on using hashes here.

File details

Details for the file async_call-0.1.2-py2-none-any.whl.

File metadata

  • Download URL: async_call-0.1.2-py2-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for async_call-0.1.2-py2-none-any.whl
Algorithm Hash digest
SHA256 19dde8d0d787609e285cd483343da04f120d919699746c966bb6708472f2ac59
MD5 eb36ecda2dc10ac79f4a91d211731c3a
BLAKE2b-256 8656aa1fbd0af24fd22c250a283d8436619169b9b5e66b0cf12d00ff4b839344

See more details on using hashes here.

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