I am not getting TimeoutException if I don't enter any text within 5 seconds. The below code method will call getMsg() and wait for text input. I added 'timeout( 5, TimeUnit.SECONDS )' to wait only for 5 secs for the input. I want to show timeout error in case user did not enter msg with in 5 seconds.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.concurrent.TimeUnit;
import rx.Observable;
public class TestRx {
public static void main( String[] args ) throws IOException {
Observable.just( getMsg() )
.timeout( 5, TimeUnit.SECONDS )
.subscribe( System.out::println,
e -> e.printStackTrace() );
System.out.println( "End..." );
}
private static String getMsg() throws IOException {
BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
System.out.print( "Enter a msg:" );
String msg = reader.readLine();
return msg;
}
}