Using promise to solve concurrency problem