Created
April 24, 2019 11:00
-
-
Save Mayankgupta688/1a0f602718b68542e5bc8131cf063024 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable } from 'rxjs'; | |
var randomNumberGenerator = Observable.create(function(observer) { | |
setTimeout(function() { | |
var randomNumber = Math.floor(Math.random() * 100); | |
if(randomNumber == 13) { | |
observer.error("Incorrect Random Number Generated"); | |
} else if(randomNumber == 99) { | |
observer.complete(); | |
} else { | |
observer.next(randomNumber); | |
} | |
}, 1000); | |
}); | |
randomNumberGenerator.subscribe({ | |
next: function(data) { | |
console.log("Input Data is: " + data) | |
}, error: function(errorMessage) { | |
console.log("Recieved the error with following message: " + errorMessage); | |
}, complete: function() { | |
console.log("Observable has completed Execution"); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment