Add optional timeout

Added an optional timeout value so that current implementations will not break.
Any idea how to test this properly?