TDAsyncIO.tox is a Component for using the asyncio module in TouchDesigner without blocking the TD's main thread by running the event loop only once at the start of every frame.
- Active - The Event Loop can run asynchronous tasks while 'Active' is enabled
- Cancel All Tasks - Cancel all tasks you created.
@property
def Loop(self):
"""
Returns the Loop specified for this instance of TDAsyncIO.
Each instance of the COMP has itws own eventLoop.
"""
pass
def RunSync(self, coroutines: Union[List[Awaitable], Awaitable]) -> List[Any]:
"""
Runs all passed routines concurrent, but stalls the process and returns the returnvalues as a list.
"""
pass
def RunAsync(self, coroutines: Union[List[Awaitable], Awaitable]) -> List[asyncio.Task]:
"""
Runs all routines concurrently and returns a list of tasks.
"""
pass
def Cancel(self, killList=[]):
"""
Cancels all tasks currently active or the defines task in the list.
"""
passimport asyncio
async def test():
await asyncio.sleep(3)
print('hello world')
# Run coroutine
routineFutures = op("TDAsyncIO").RunAsync(test())
routineResult = op("TDAsyncIO").RunSync(test())
async def dealyedPrint(text):
await asyncio.sleep(1)
print(text)
several = op("TDAsyncIO").RunAsync([
delayedPrint("Foo"), delayedPrint("Bar")
])
# Cancel all tasks
op("TDAsyncIO").Cancel()