Created
February 6, 2018 22:55
-
-
Save xavierlepretre/8ee58bc9d49823a3343ccbcdc3a18298 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
"use strict"; | |
const Rx = require('rx'); | |
module.exports = function addFilterObservableToWeb3(web3) { | |
web3.eth.filterObservable = function(_options) { | |
const filter = web3.eth.filter(_options); | |
return Rx.Observable.create(function(observer) { | |
filter.watch(function(err, result) { | |
if (!err) { | |
observer.onNext(result); | |
} else { | |
observer.onError(err); | |
} | |
}); | |
return function() { | |
try { | |
filter.stopWatching(() => { }); | |
} catch (error) { | |
console.log("Geth probably disappeared early", error); | |
} | |
}; | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And you use it thus: