# AsyncRequest

from direct.distributed.AsyncRequest import AsyncRequest

This class is used to make asynchronos reads and creates to a database.
You can create a list of self.neededObjects and then ask for each to be read or created, or if you only have one object that you need you can skip the self.neededObjects because calling askForObject or createObject will set the self.neededObjects value for you.
Once all the objects have been read or created, the self.finish() method will be called. You may override this function to run your code in a derived class.
If you wish to queue up several items that you all need before the finish method is called, you can put items in self.neededObjects and then call askForObject or createObject afterwards. That way the _checkCompletion will not call finish until after all the requests have been done.
If you need to chain serveral object reads or creates, just add more entries to the self.neededObjects dictionary in the self.finish function and return without calling AsyncRequest.finish(). Your finish method will be called again when the new self.neededObjects is complete. You may repeat this as necessary.

## Inheritance:

AsyncRequest: DirectObject
DirectObject:

## Methods of AsyncRequest:

__init__
_checkCompletion
_doCreateObject
askForObject
askForObjectField
createObject
createObjectId
delete
finish
timeout

## Methods of DirectObject:

__init__
accept
acceptOnce
ignore
ignoreAll
isAccepting
isIgnoring

__init__ def __init__(self, air, replyToChannelId=None, timeout=DefaultTimeout) air is the AI Respository. replyToChannelId may be an avatarId, an accountId, or a channelId. timeout is how many seconds to wait before aborting the request.

_checkCompletion def _checkCompletion(self, name, context, distObj) This checks whether we have all the needed objects and calls finish() if we do.

_doCreateObject def _doCreateObject(self, name, className, values, doId) Undocumented function.

askForObject def askForObject(self, doId, context=None) Request an already created object, i.e. read from database.

askForObjectField def askForObjectField(self, dclassName, fieldName, doId, key=None, context=None) Request an already created object, i.e. read from database.

createObject def createObject(self, name, className, databaseId=None, values=None, context=None) Create a new database object. You can get the doId from within your self.finish() function. This functions is different from createObjectId in that it does generate the object when the response comes back. The object is added to the doId2do and so forth and treated as a full regular object (which it is). This is useful on the AI where we really do want the object on the AI.

createObjectId def createObjectId(self, name, className, values=None, context=None) Create a new database object. You can get the doId from within your self.finish() function. This functions is different from createObject in that it does not generate the object when the response comes back. It only tells you the doId. This is useful on the UD where we don't really want the object on the UD, we just want the object created and the UD wants to send messages to it using the ID.

delete def delete(self) Undocumented function.

finish def finish(self) This is the function that gets called when all of the needed objects are in (i.e. all the askForObject and createObject requests have been satisfied). If the other requests timeout, finish will not be called.

timeout def timeout(self, task) If this is called we have not gotten the needed objects in the timeout period. Derived classes should inform the user or whomever and then call this base method to cleanup.

__init__ def __init__(self) Undocumented function.

accept def accept(self, event, method, extraArgs=[]) Undocumented function.

acceptOnce def acceptOnce(self, event, method, extraArgs=[]) Undocumented function.

ignore def ignore(self, event) Undocumented function.

ignoreAll def ignoreAll(self) Undocumented function.

isAccepting def isAccepting(self, event) Undocumented function.

isIgnoring def isIgnoring(self, event) Undocumented function.