A

The main problem happens cuz
dialog.show method is non-blocking method, so while u call perdirValoracion dialog is created, shown and value of rating var is returned. onClick call sets rating value when u click OK button, but decision value in eliminarLibro method is already set to previous rating value. That's why your action of delete or refresh is executing at next dialog creation call(even before secondly created dialog is shown)

