1# Async Event RPC Example 2 3This example shows you how to use the @AsyncRpc annotation of Mobly snippet lib 4to handle asynchronous callbacks. 5 6See the source code in `ExampleAsyncSnippet.java` for details. 7 8## Running the example code 9 10This folder contains a fully working example of a standalone snippet apk. 11 121. Compile the example 13 14 ./gradlew examples:ex3_async_event:assembleDebug 15 161. Install the apk on your phone 17 18 adb install -r ./examples/ex3_async_event/build/outputs/apk/debug/ex3_async_event-debug.apk 19 201. Use `snippet_shell` from mobly to trigger `tryEvent()`: 21 22 snippet_shell.py com.google.android.mobly.snippet.example3 23 24 >>> handler = s.tryEvent(42) 25 >>> print("Not blocked, can do stuff here") 26 >>> event = handler.waitAndGet('AsyncTaskResult') # Blocks until the event is received 27 28 Now let's see the content of the event 29 30 >>> import pprint 31 >>> pprint.pprint(event) 32 { 33 'callbackId': '2-1', 34 'name': 'AsyncTaskResult', 35 'time': 20460228696, 36 'data': { 37 'exampleData': "Here's a simple event.", 38 'successful': True, 39 'secretNumber': 12 40 } 41 } 42