Asynchronous

Promise

mypygui.core.asynchronous.async_tools.Promise

Promise.state

Promise.state
int
The state of the promise

Promise.result

Promise.result
any
The resolved value or the cancellation reason. It is None by default

Promise.then

Promise.then
(fn, provide_purity?) → Promise
Subscribes to the resolution of the promise
Parameters:
  • callback : (result, purity?)
    NOTE: The purity is only given if `provide_purity` was set to True
  • provide_purity : bool
    Set to True to know if the promise was resolved before the 'then' method was applied on it
Returns:
The same promise

Promise.catch

Promise.catch
(fn, provide_purity?) → Promise
Subscribes to the cancellation of the promise
Parameters:
  • callback : (reason, purity?)
    NOTE: The purity is only given if `provide_purity` was set to True
  • provide_purity : bool
    Set to True to know if the promise was resolved before the 'catch' method was applied on it
Returns:
The same promise

Promise.await_result

Promise.await_result
( ) → None
Holds the thread till the promise has been cancelled or resolved

Promise.resolve

Promise.resolve
(result : any) → None
Resolves the promise

Promise.cancel

Promise.cancel
(reason : any) → None
Cancels the promise

Promise.ONGOING

Promise.ONGOING
int (static)
The state of a promise which has not been resolved or cancelled

Promise.SUCCESS

Promise.SUCCESS
int (static)
The state of a promise which has been resolved

Promise.FAILURE

Promise.FAILURE
int (static)
The state of a promise which has been cancelled

Signal

mypygui.core.asynchronous.async_tools.Signal


Basicaly just threading.Event

Miscellaneous Functions

asynchronously_run

mypygui.core.asynchronous.async_tools
asynchronously_run
(fn, args?, kwargs?, daemon?, name?) → None
Runs the provided function on a new thread
NOTE: Setting `daemon` to False will allow the thread to run even after the main thread has ended

Decorators

thenify

thenify
(fn, name?) → fn
Runs the function on a new thread whenever it is called and returns a promise that will get resolved when function finishes execution
NOTE: Raise an exception to cancel the promise from within the function
NOTE: The promise will not be provided to the thenified function

promisify

promisify
(fn, name?) → fn
Runs the function on a new thread whenever it is called and returns a promise that will get resolved when function finishes execution NOTE: The function must take in a parameter called `_promise` which contains the promise that is given in place of the funciton NOTE: The function must resolve or cancel the promise on its own

asyncify

asyncify
(fn, name?) → fn
Marks a function to be run asynchronously (does not create any promises)