Skip to main content

Result and friends: callable objects which will receive a value at a later point in time.

Project description

A Result is the base class for several callable subclasses which will receive values at a later point in time, and can also be used standalone without subclassing.

A call to a Result will block until the value is received or the Result is cancelled, which will raise an exception in the caller. A Result may be called by multiple users, before or after the value has been delivered; if the value has been delivered the caller returns with it immediately. A Result’s state may be inspected (pending, running, ready, cancelled). Callbacks can be registered via an Asychron’s .notify method.

An incomplete Result can be told to call a function to compute its value; the function return will be stored as the value unless the function raises an exception, in which case the exception information is recorded instead. If an exception occurred, it will be reraised for any caller of the Result.

Trite example:

R = Result(name="my demo")

Thread 1:
  value = R()
  # blocks...
  print(value)
  # prints 3 once Thread 2 (below) assigns to it

Thread 2:
  R.result = 3

Thread 3:
  value = R()
  # returns immediately with 3

You can also collect multiple Results in completion order using the report() function:

Rs = [ ... list of Results or whatever type ... ]
...
for R in report(Rs):
  x = R()     # collect result, will return immediately
  print(x)    # print result

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

cs.result-20171030.1.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file cs.result-20171030.1.tar.gz.

File metadata

File hashes

Hashes for cs.result-20171030.1.tar.gz
Algorithm Hash digest
SHA256 0534ffdd0176e43ac4b1995f4c0cc030e7f3842fbc4cee58a4c1834db932ca2b
MD5 dd92ad3f8316858f823f52f23ec35eb6
BLAKE2b-256 a2581c40b0e597590cc73de2db7ac16a567aca62f6e8d6064018d0f991b34d5a

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