Async Adapter

A MicroArchitecture pattern.

An asynchronous adapter, adapts a synchronous environment to an asynchronous one.

In a synchronous environment a caller expects the execution thread to only return when there is a result. In the asynchronous case the execution thread returns immediately.

This adapter encapsulates some logic that traps the calling thread, gets the result from the called thread when it is ready, fills in the return object and gives it back to the calling thread.

A more functional version implements timeouts though this needs an underlying object that can handle errors.

This pattern is often used to cross execution boundaries e.g. threaded, networked, multiprocess. The basic adapter will need to have some form of internal thread available for the return cycle. The easiest choice is to steal the caller's thread since it doesn't need it till the return value is there anyway.


The corresponding twin to the above arrangement [maybe do as separate page?] adapts an asynchronous call to a synchronous call process. The caller expects an immediate return. A separate thread must return the result somehow, usually using a callback to the originating object. The adapter here must have its own thread. We cannot capture the callers thread which returns straight away. The callback method is either statically linked or passed as a parameter (possibly in system thread information i.e. semi-implicitly).

The callback is fired with the result and status when it returns. Timeouts can be communicated. There is a chance that the calling object has already gone away, so the adapter needs to be a little careful.

The thread usually waits until the next call wakes it up.


Related to... PushPullAdapter and PullPushAdapter.


EditText of this page (last edited July 9, 2001) or FindPage with title or text search