Simulating Request Delay With RxJS


We are requesting post data of type Post and we wish to simulate the retrieval of a single Post instance.


Lets first create the Post type:

type Post = { title: string, content: string };

Next use the RxJS delay operator to simulate the delay in retrieving the Post instance like this:

const post:Observable<Post> = of( 
{title: 'Simulating HTTP Requests',
content: 'This is off the hook!!'})

The Post instance is logged after the 2 second delay introduced by delay(2000) .




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ole Ersoy

Ole Ersoy

Founder of Firefly Semantics Corporation