public IPromise atomicQuery ( String key , RLFunction < Record , Object > action ) { Record rec = getStore ( ) . get ( key ) ; if ( rec == null ) { final Object apply = action . apply ( rec ) ; if ( apply instanceof ChangeMessage ) { receive ( ( ChangeMessage ) apply ) ; } return new Promise ( apply ) ; } else { PatchingRecord pr = new PatchingRecord ( rec ) ; final Object res = action . apply ( pr ) ; if ( res instanceof ChangeMessage ) { receive ( ( ChangeMessage ) res ) ; } else { UpdateMessage updates = pr . getUpdates ( 0 ) ; if ( updates != null ) { receive ( updates ) ; } } return new Promise ( res ) ; } }
apply the function to the record with given key and return the result inside a promise