adoptation of ratelimit function from stackoverflow for promises