make tx run in parallel

pull/1/head
yann300 8 years ago
parent 980856e424
commit 748178d2c4
  1. 28
      src/app/execution/txRunner.js

@ -14,31 +14,17 @@ function TxRunner (executionContext, vmaccounts, opts) {
if (this.executionContext.isVM()) { if (this.executionContext.isVM()) {
this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block. this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block.
} }
this.running = false this.pendingTxs = {}
this.pendingTxs = []
this.vmaccounts = vmaccounts this.vmaccounts = vmaccounts
} }
TxRunner.prototype.rawRun = function (args, cb) { TxRunner.prototype.rawRun = function (args, cb) {
this.pendingTxs.push({tx: args, cb: cb}) run(this, args, Date.now(), cb)
this.execute()
} }
TxRunner.prototype.execute = function () { TxRunner.prototype.execute = function (args, callback) {
var self = this var self = this
if (this.running || this.pendingTxs.length === 0) {
return
}
var args = this.pendingTxs[0].tx
var cb = this.pendingTxs[0].cb
this.pendingTxs.shift()
var callback = function (error, result) {
cb(error, result)
self.running = false
self.execute()
}
this.running = true
var from = args.from var from = args.from
var to = args.to var to = args.to
var data = args.data var data = args.data
@ -153,4 +139,12 @@ function tryTillResponse (web3, txhash, done) {
}) })
} }
function run (self, tx, stamp, callback) {
self.pendingTxs[stamp] = tx
self.execute(tx, (error, result) => {
delete self.pendingTxs[stamp]
callback(error, result)
})
}
module.exports = TxRunner module.exports = TxRunner

Loading…
Cancel
Save