Asynchronous Method Invocation
An Asynchronous Method Invocation is a software design pattern that allows a method call to return immediately without waiting for the called method to complete its execution.
- Context:
- It can (typically) be useful in scenarios where blocking the calling thread is undesirable, such as in user interface applications or when performing I/O operations.
- It can (typically) enable Thread (Computer Science) to continue execution without being blocked by long-running methods.
- It can (often) improve the responsiveness of User Interface applications by allowing the UI to remain interactive.
- It can range from being a simple Callback Function to more complex Future and Promise implementations.
- It can allow Concurrency in Asynchronous Programming environments, facilitating efficient resource utilization.
- ...
- Example(s):
- An Asynchronous API that handles network requests without blocking the main thread.
- ...
- Counter-Example(s):
- Synchronous Method Invocations, which block the calling thread until the called method has completed.
- See: Blocking (Computing), Thread (Computer Science), Computer Programming, Software Design Pattern.
References
2024
- (Wikipedia, 2024) ⇒ https://en.wikipedia.org/wiki/Asynchronous_method_invocation Retrieved:2024-6-20.
- In multithreaded computer programming, asynchronous method invocation (AMI), also known as asynchronous method calls or the asynchronous pattern is a design pattern in which the call site is not blocked while waiting for the called code to finish. Instead, the calling thread is notified when the reply arrives. Polling for a reply is an undesired option.
2024
- (Wikipedia, 2024) ⇒ https://en.wikipedia.org/wiki/Asynchronous_method_invocation#Background Retrieved:2024-6-20.
- AMI is a design pattern for asynchronous invocation of potentially long-running methods of an object.[1]
It is equivalent to the IOU ("I owe you") pattern described in 1996 by Allan Vermeulen. In most programming languages a called method is executed synchronously, i.e. in the thread of execution from which it is invoked. If the method takes a long time to complete, e.g. because it is loading data over the internet, the calling thread is blocked until the method has finished. When this is not desired, it is possible to start a "worker thread" and invoke the method from there. In most programming environments this requires many lines of code, especially if care is taken to avoid the overhead that may be caused by creating many threads. AMI solves this problem in that it augments a potentially long-running ("synchronous") object method with an "asynchronous" variant that returns immediately, along with additional methods that make it easy to receive notification of completion, or to wait for completion at a later time. One common use of AMI is in the active object design pattern. Alternatives are synchronous method invocation and future objects.
An example for an application that may make use of AMI is a web browser that needs to display a web page even before all images are loaded.
Since method is a special case of procedure, asynchronous method invocation is a special case of asynchronous procedure call.
- AMI is a design pattern for asynchronous invocation of potentially long-running methods of an object.[1]
- ↑ Cite error: Invalid
<ref>
tag; no text was provided for refs namedAsync.34.2#71139