Simple implementation for blpop and brpop