Implement workaround a race condition that happens when calling next on generator.