My implemention of javascript `when`