merge sigwait code