-
Notifications
You must be signed in to change notification settings - Fork 778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Promises #252
Comments
I like this idea. It is backwards compatible as well! Pending any reservations by @holgerd77 @axic , I would say go ahead :) |
Would also very much support this, great that you want to implement it! 😄 Could you post some code snippet with 10LOC or so on how you think/plan this would look like when being called with promises from the outside? |
With promises, the code can be executed in 3 ways: The existing way with callbacks vm.runCode({
code: Buffer.from(code, 'hex'), // code needs to be a Buffer
gasLimit: Buffer.from('ffffffff', 'hex')
}, function(err, results){
console.log('returned: ' + results.return.toString('hex'));
}) Using promises vm.runCode({
code: Buffer.from(code, 'hex'), // code needs to be a Buffer
gasLimit: Buffer.from('ffffffff', 'hex')
})
.then(function(results){
console.log('returned: ' + results.return.toString('hex'));
})
.catch(function(err){
console.error(err);
}) Or using async/await try {
var results = await vm.runCode({
code: Buffer.from(code, 'hex'), // code needs to be a Buffer
gasLimit: Buffer.from('ffffffff', 'hex')
});
console.log('returned: ' + results.return.toString('hex'));
} catch (err) {
console.error(err);
} |
Based on the feedback, I made a cleaner implementation in #273 |
@jwasinger actually I made a Promised (no async dep) version of all etherumjs repos with @wanderer in around last year may |
@Silur Tell us more, is this code locked on an USB-Stick in a secret cupboard in a forgotten Lisbon library?? 😄 🔑 |
Addressed in #546, will close. |
…-release v7.0.1 release / Downgrade bn.js re-export from v5 to v4
I would love if the API supported returning Promises as an alternative to callbacks. This would be implemented by returning Promises if no callback is provided.
I'm happy to add the feature and submit a PR if you're open to it!
The text was updated successfully, but these errors were encountered: