Convert Promises based async code to use Generator