Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const createFromEthereumBlock = (blockNumber) => (initial, dataFn, fn) => {
let disposer
let isBusy = observable.box(false)
const resource = fromResource(
(sink) => {
disposer = reaction(
() => [dataFn(), blockNumber],
async ([data]) => {
try {
runInAction(() => isBusy.set(true))
sink(await fn(data))
} catch (error) {
// @TODO(handle errors)
console.error(error)
debugger
} finally {
runInAction(() => isBusy.set(false))
}
},
{ fireImmediately: true }
constructor() {
this.data = fromResource(
async sink => {
this.socket = new WebSocketConnection();
await this.socket.subscribe('data');
const result = await this.socket.get();
sink(result);
},
() => {
this.socket.unsubscribe('data');
this.socket = null;
},
);
}
}