add optional timeout parameter

In certain circumstances the data fetching could hang infinitely. With this optional timout parameter, one can prevent it.