Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Queue = require('better-queue');
- var BtcClient = require('bitcoin-core')
- class Test {
- constructor() {
- this.methods = ['getSomething', 'getBalance', 'batch', 'getAddress', 'getBlock', 'getBlockCount', 'getBestBlockHash', 'getBestBlock', 'getBlockCount', 'getAddresses']
- this.queue = new Queue(this.execute.bind(this), { maxRetries: 10, retryDelay: 1000 })
- //this.tmp = {}
- //this.tmp['btc'] = { 'test': function(){console.log("works") }}
- }
- async getSomething (a, b) {
- // this.tmp['btc']['test']()
- console.log("yay ", a, b)
- }
- async execute (input) {
- try {
- return await this[input.cmd](...input.args)
- } catch (e) {
- // can't throw errors in here
- console.log(e)
- }
- }
- handle(msg) {
- if (this.methods.indexOf(msg.cmd) > -1) {
- let id = this.queue.push(msg)
- return id;
- } else {
- }
- }
- }
- let d = new Test()
- try {
- a = d.handle({id:'idhere', cmd: "getSomething", coin: 'CLAM', args: ['a', 'b']} )
- if(a.status == 'created') {
- console.log('jesus chist, superstar', a.status)
- }
- } catch (e) {
- console.log("a error ", e)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement