Composing promises with logic