Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ensuring Cleanup with Finally
- We've already covered the try/catch part of try/catch/finally, so what about finally? We have the finally operator which calls a function after the source sequence terminates gracefully or exceptionally. This is useful if you are using external resources or need to free up a particular variable upon completion.
- In this example, we can ensure that our WebSocket will indeed be closed once the last message is processed.
- var socket = new WebSocket('ws://someurl', 'xmpp');
- var source = Rx.Observable.from(data)
- .finally(() => socket.close());
- var subscription = source.subscribe(
- data => {
- socket.send(data);
- }
- );
Add Comment
Please, Sign In to add comment