Skip to content

Instantly share code, notes, and snippets.

@obscuren
Created September 30, 2014 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save obscuren/3779dc005c981d9977e7 to your computer and use it in GitHub Desktop.
Save obscuren/3779dc005c981d9977e7 to your computer and use it in GitHub Desktop.
promises vs regular async
eth.getKey(function(key) {
eth.getStorageAt("someaddr", "somelocation", function(address) {
eth.compile("thiscode", function(code) {
eth.transact({to: address, from: key, gas: 10000, gasPrice: eth.gasPrice, data:[code]}, function(tx){
console.log(tx)
})
})
})
})
// VS
eth.transact({
to: eth.storageAt("a", "b"),
from: eth.key,
gas: 1000,
gasPrice: eth.gasPrice,
data: eth.compile("code"),
}).
then(function(tx) {
console.log(tx);
});
@prashantpawar
Copy link

Your second example with a callback.

eth.transact({
  to: eth.storageAt("a", "b"),
  from: eth.key,
  gas: 1000,
  gasPrice: eth.gasPrice,
  data: eth.compile("code"),
},
function(tx) {
  console.log(tx);
});

There are many better ways of demonstrating how promises are awesome, but in your example promises are actually not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment