Example using  promises in a loop