In many RPC situations, synchronization between the two communicating endpoints is a matter of correctly designing the RPC application: when synchronization is needed, requests (which are blocking) should be used; when it isn’t, notifications should suffice. However, when Emacs acts as one of these endpoints, asynchronous events (e.g., timer- or process-related) may be triggered while there is still uncertainty about the state of the remote endpoint. Furthermore, acting on these events may only sometimes demand synchronization, depending on the event’s specific nature.
jsonrpc-requestやjsonrpc-async-requestにたいするキーワード引数:deferredは特定のリクエストに同期が必要なことを呼び出し側が示せるようにして、リクエストの実際の発行は何らかの条件が満足されるまで遅延できるようにデザインされています。あるリクエストへの:deferred指定はリクエストが遅延されるのではなく、遅延される可能性があることを意味します。リクエストが即座に送信されなければ、エンドポイントにたいして他のメッセージの受信や送信を行う際のように、通信中の特定タイミングでjsonrpcはリクエストを送る新たな試みを行います。
リクエストを送信するすべての試みの前にアプリケーション固有の条件がチェックされます。jsonrpcライブラリーがこれらの条件を知ることはできないので、それらを指定するためにプログラムはジェネリック関数jsonrpc-connection-ready-pを使用できます(ジェネリック関数を参照)。この関数のデフォルトメソッドはtをリターンしますが、これをオーバーライドして渡された引数(
jsonrpc-connectionオブジェクト。概観を参照)とキーワード引数:deferredとして渡されたすべて値にもとづいてnilをリターンするメソッドを追加できます。