-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Deployment scripts with async/await #501
Comments
I have my tests working with async/await right now, but I do have difficulty using async/await syntax in my migrations scripts for some reason. Using Node v8.1.3. |
Happens to me as well, Node 8.1.3, Truffle 3.4.8. |
+1 |
Same here, I had symptoms of #386 when trying to use async/await in migrations |
When writing migrations, remember that your migration function stages deployment tasks -- it's not intended to run those tasks at execution time of the migration function. This behavior and Promise structure of migrations was built in a time when We plan on making migrations work with 2_some_migration.js var SomeContract = artifacts.require("SomeContract");
// An async function
const someAsyncFunction = async function someAsyncFunction() {
// ...
};
// Your actual migration
module.exports = (deployer) => {
deployer.deploy(SomeContract).then(() => await someAsyncFunction())
// Alternatively, just start a chain without a deployment
deployer.then(() => await someAsyncFunction())
} This will ensure your Again, we will be revamping this in the future. Would love to hear your thoughts on how migrations could be made easier. |
Edit: I wrote that code on the fly; didn't test it. Please correct me if there are any typos! |
I'm trying to use this workaround but it seems that it doesn't have change to work. It's not possible to wrap call with await inside non-async function. So |
@rodiazet what he meant was
I wrapped all this together like
Hope this helps! Shout out to http://y-nakajo.hatenablog.com/entry/2018/01/15/174743 |
@shkfnly Thanks for sharing 👍 |
…g migrations. This resolves: dappuniversity#3 This bug was caused by the way in which the migrations steps are added to the promise chain. More can be read about this issue here: trufflesuite/truffle#501
Yes, i encountered this issue with node v8.10.0, it look like await() don't return but the test flow exited normally. Finally i upgrade nodejs to 9.11.1 and then run smoothly |
Thank you for raising this issue! It has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you would like to keep this issue open, please respond with information about the current state of this problem. |
There has been no new activity on this issue since it was marked as stale 7 days ago, so it is being automatically closed. If you'd like help with this or a different problem, please open a new issue. Thanks! |
hi dear
how can i solved it?? |
It is possible to configure test scripts to work with async/await. (JavaScript test scripts, of course).
It would be amazing to have the same for deployment scripts. Because all that
.then
really destroy readability of deployment scripts.The text was updated successfully, but these errors were encountered: