package Ġel ast iko Ċ Ċ import Ġnl . k omp onent s . kov enant . Deferred Ċ import Ġnl . k omp onent s . kov enant . Promise Ċ import Ġnl . k omp onent s . kov enant . deferred Ċ import Ġorg . elasticsearch . action . ActionListener Ċ import Ġorg . elasticsearch . action . Action Request Ċ import Ġorg . elasticsearch . action . Action RequestBuilder Ċ import Ġorg . elasticsearch . action . Action Response Ċ Ċ public Ġclass ĠWr apped Throwable Exception ( cause : ĠThrowable ) Ġ: ĠException ( cause . message , Ġcause ) Ċ Ċ class ĠDeferred ActionListener < T >( deferred : ĠDeferred < T , ĠException >) Ġ: ĠActionListener < T > Ġ{ ĊĊĠĠĠ Ġvar Ġdeferred : ĠDeferred < T , ĠException > Ġ= Ġdeferred ĊĊĠĠĠ Ġoverride Ġfun Ġon Response ( res : ĠT ) Ġ{ ĊĠĠĠĠĠĠĠ Ġdeferred . resolve ( res ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Failure ( e : ĠThrowable ) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhen Ġ( e ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠException Ġ-> Ġdeferred . reject ( e ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġdeferred . reject ( Wrapped Throwable Exception ( e )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ public Ġfun Ġ< T Request Ġ: ĠAction Request <* >, ĠT Response Ġ: ĠAction Response , ĠT RequestBuilder Ġ: ĠAction RequestBuilder < T Request , ĠT Response , ĠT RequestBuilder >> ĠAction RequestBuilder < T Request , ĠT Response , ĠT RequestBuilder >. to Promise (): ĠPromise < T Response , ĠException > Ġ{ ĊĠĠĠ Ġval Ġdeferred Ġ= Ġdeferred < T Response , ĠException >() ĊĠĠĠ Ġthis . execute ( Deferred ActionListener ( deferred )) ĊĠĠĠ Ġreturn Ġdeferred . promise Ċ } ĊĊ