A Simple 'when' function for node and the browser