public < R > Promise < T > chain ( final Function < T , Promise < R > > res ) { final Promise < T > self = this ; return new Promise <> ( resolver -> { self . then ( t -> { Promise < R > chained = res . apply ( t ) ; chained . then ( t2 -> resolver . result ( t ) ) ; chained . failure ( e -> resolver . error ( e ) ) ; } ) ; self . failure ( e -> resolver . error ( e ) ) ; } ) ; }
Chaining result to next promise and returning current value as result promise