Skip to content

Instantly share code, notes, and snippets.

@trxcllnt
Created September 16, 2016 00:27
Show Gist options
  • Save trxcllnt/a2adab473947863ee48b01c26b8fae83 to your computer and use it in GitHub Desktop.
Save trxcllnt/a2adab473947863ee48b01c26b8fae83 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<!-- put markup and other contents here -->
<div id="app"></div>
</body>
</html>
import { Observable } from 'rxjs';
const someObservableThatMightBeSyncOrAsync = Observable.create((subscriber) => {
let id, isSync = false && Math.random() < 0.5;
if (isSync) {
subscriber.next(`oops I'm synchronous`);
} else {
id = setTimeout(() => {
subscriber.next(`nice I'm async`);
}, 100);
}
return () => {
if (id) {
clearTimeout(id);
id = null;
}
}
});
try {
someObservableThatMightBeSyncOrAsync.subscribe(
(x) => {
throw "something really bad happened";
},
(e) => {
console.log(`handled the error '${e}' nice`);
}
);
} catch(e) {
console.error(`sync emission so catch won't work :(`);
}
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"rxjs": "5.0.0-beta.11"
}
}
"use strict";
var _rxjs = require("rxjs");
var someObservableThatMightBeSyncOrAsync = _rxjs.Observable.create(function (subscriber) {
var id = void 0,
isSync = false && Math.random() < 0.5;
if (isSync) {
subscriber.next("oops I'm synchronous");
} else {
id = setTimeout(function () {
subscriber.next("nice I'm async");
}, 100);
}
return function () {
if (id) {
clearTimeout(id);
id = null;
}
};
});
try {
someObservableThatMightBeSyncOrAsync.subscribe(function (x) {
throw "something really bad happened";
}, function (e) {
console.log("handled the error '" + e + "' nice");
});
} catch (e) {
console.error("sync emission so catch won't work :(");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment