How to seperate function with await The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceIs there an “exists” function for jQuery?How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?var functionName = function() vs function functionName() How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?
First use of “packing” as in carrying a gun
Why did all the guest students take carriages to the Yule Ball?
Segmentation fault output is suppressed when piping stdin into a function. Why?
What are these Gizmos at Izaña Atmospheric Research Center in Spain?
system() function string length limit
High Q peak in frequency response means what in time domain?
How can I protect witches in combat who wear limited clothing?
What is this lever in Argentinian toilets?
Typeface like Times New Roman but with "tied" percent sign
He got a vote 80% that of Emmanuel Macron’s
How is simplicity better than precision and clarity in prose?
Searching for a differential characteristic (differential cryptanalysis)
How many people can fit inside Mordenkainen's Magnificent Mansion?
How to copy the contents of all files with a certain name into a new file?
Why can't devices on different VLANs, but on the same subnet, communicate?
I could not break this equation. Please help me
What aspect of planet Earth must be changed to prevent the industrial revolution?
Working through the single responsibility principle (SRP) in Python when calls are expensive
When did F become S in typeography, and why?
The following signatures were invalid: EXPKEYSIG 1397BC53640DB551
Derivation tree not rendering
Is there a writing software that you can sort scenes like slides in PowerPoint?
Who or what is the being for whom Being is a question for Heidegger?
How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time
How to seperate function with await
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceIs there an “exists” function for jQuery?How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?var functionName = function() vs function functionName() How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I just switch from php into full time js. I try to clean code in javascript function but still confuse how to deal with it
for(let i in allEmpData)
let emp = allEmpData[i]
if(empData == null)
const addEmp = new Employee()
this.addEmpFn(addEmp, emp)
if(empData != null)
this.addEmpFn(empData, emp)
I call function addEmpFn because I put create/update code in thier here is my function addEmpFn
addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
the error said :
Unexpected token return await
I want to do something like this but In the clean code , seperate function
for(let i in allEmpData)
const empData = await Employee.query()
.where('id',1)
.first();
let emp = allEmpData[i]
if(empData == null)
const addEmp = new Employee()
addEmp.name = emp.name
return await empData.save()
if(empData != null)
empData.name = emp.name
return await empData.save()
javascript node.js adonis.js
add a comment |
I just switch from php into full time js. I try to clean code in javascript function but still confuse how to deal with it
for(let i in allEmpData)
let emp = allEmpData[i]
if(empData == null)
const addEmp = new Employee()
this.addEmpFn(addEmp, emp)
if(empData != null)
this.addEmpFn(empData, emp)
I call function addEmpFn because I put create/update code in thier here is my function addEmpFn
addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
the error said :
Unexpected token return await
I want to do something like this but In the clean code , seperate function
for(let i in allEmpData)
const empData = await Employee.query()
.where('id',1)
.first();
let emp = allEmpData[i]
if(empData == null)
const addEmp = new Employee()
addEmp.name = emp.name
return await empData.save()
if(empData != null)
empData.name = emp.name
return await empData.save()
javascript node.js adonis.js
add a comment |
I just switch from php into full time js. I try to clean code in javascript function but still confuse how to deal with it
for(let i in allEmpData)
let emp = allEmpData[i]
if(empData == null)
const addEmp = new Employee()
this.addEmpFn(addEmp, emp)
if(empData != null)
this.addEmpFn(empData, emp)
I call function addEmpFn because I put create/update code in thier here is my function addEmpFn
addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
the error said :
Unexpected token return await
I want to do something like this but In the clean code , seperate function
for(let i in allEmpData)
const empData = await Employee.query()
.where('id',1)
.first();
let emp = allEmpData[i]
if(empData == null)
const addEmp = new Employee()
addEmp.name = emp.name
return await empData.save()
if(empData != null)
empData.name = emp.name
return await empData.save()
javascript node.js adonis.js
I just switch from php into full time js. I try to clean code in javascript function but still confuse how to deal with it
for(let i in allEmpData)
let emp = allEmpData[i]
if(empData == null)
const addEmp = new Employee()
this.addEmpFn(addEmp, emp)
if(empData != null)
this.addEmpFn(empData, emp)
I call function addEmpFn because I put create/update code in thier here is my function addEmpFn
addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
the error said :
Unexpected token return await
I want to do something like this but In the clean code , seperate function
for(let i in allEmpData)
const empData = await Employee.query()
.where('id',1)
.first();
let emp = allEmpData[i]
if(empData == null)
const addEmp = new Employee()
addEmp.name = emp.name
return await empData.save()
if(empData != null)
empData.name = emp.name
return await empData.save()
javascript node.js adonis.js
javascript node.js adonis.js
asked Mar 22 at 6:46
TryHardTryHard
696
696
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
You need to assign function as async as follows:
async addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
why you need an async await here?
– AZ_
Mar 22 at 7:07
add a comment |
await keyword only works inside async functions. so you have to write async keyword before function declaration.
like this;
async addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
add a comment |
You don't really need an async await here, async await is needed when you want to wait for the promise to get resolved.
And also return await is an anti-pattern in JS until you don't want to use try-catch around.
Following code is the way to go, works same as the accepted answer.
addEmpFn(empData, emp)
empData.name = emp.name
return empData.save()
1
Thank you, I just wanted to write the same thing.
– Woozar
Mar 22 at 9:03
add a comment |
Try to mention async before your funtion like below I mentioned
async addEmpFn(empData, emp)
empData.name = emp.name;
return await empData.save();
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
1
Cool.. you come up with problem is important...happy coding
– umer sayyed
Mar 22 at 6:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294231%2fhow-to-seperate-function-with-await%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to assign function as async as follows:
async addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
why you need an async await here?
– AZ_
Mar 22 at 7:07
add a comment |
You need to assign function as async as follows:
async addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
why you need an async await here?
– AZ_
Mar 22 at 7:07
add a comment |
You need to assign function as async as follows:
async addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
You need to assign function as async as follows:
async addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
answered Mar 22 at 6:51
Shubham ChaudharyShubham Chaudhary
36917
36917
why you need an async await here?
– AZ_
Mar 22 at 7:07
add a comment |
why you need an async await here?
– AZ_
Mar 22 at 7:07
why you need an async await here?
– AZ_
Mar 22 at 7:07
why you need an async await here?
– AZ_
Mar 22 at 7:07
add a comment |
await keyword only works inside async functions. so you have to write async keyword before function declaration.
like this;
async addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
add a comment |
await keyword only works inside async functions. so you have to write async keyword before function declaration.
like this;
async addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
add a comment |
await keyword only works inside async functions. so you have to write async keyword before function declaration.
like this;
async addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
await keyword only works inside async functions. so you have to write async keyword before function declaration.
like this;
async addEmpFn(empData, emp)
empData.name = emp.name
return await empData.save()
answered Mar 22 at 6:52
Özgün ÖzenÖzgün Özen
511
511
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
add a comment |
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
add a comment |
You don't really need an async await here, async await is needed when you want to wait for the promise to get resolved.
And also return await is an anti-pattern in JS until you don't want to use try-catch around.
Following code is the way to go, works same as the accepted answer.
addEmpFn(empData, emp)
empData.name = emp.name
return empData.save()
1
Thank you, I just wanted to write the same thing.
– Woozar
Mar 22 at 9:03
add a comment |
You don't really need an async await here, async await is needed when you want to wait for the promise to get resolved.
And also return await is an anti-pattern in JS until you don't want to use try-catch around.
Following code is the way to go, works same as the accepted answer.
addEmpFn(empData, emp)
empData.name = emp.name
return empData.save()
1
Thank you, I just wanted to write the same thing.
– Woozar
Mar 22 at 9:03
add a comment |
You don't really need an async await here, async await is needed when you want to wait for the promise to get resolved.
And also return await is an anti-pattern in JS until you don't want to use try-catch around.
Following code is the way to go, works same as the accepted answer.
addEmpFn(empData, emp)
empData.name = emp.name
return empData.save()
You don't really need an async await here, async await is needed when you want to wait for the promise to get resolved.
And also return await is an anti-pattern in JS until you don't want to use try-catch around.
Following code is the way to go, works same as the accepted answer.
addEmpFn(empData, emp)
empData.name = emp.name
return empData.save()
addEmpFn(empData, emp)
empData.name = emp.name
return empData.save()
addEmpFn(empData, emp)
empData.name = emp.name
return empData.save()
answered Mar 22 at 7:06
AZ_AZ_
917310
917310
1
Thank you, I just wanted to write the same thing.
– Woozar
Mar 22 at 9:03
add a comment |
1
Thank you, I just wanted to write the same thing.
– Woozar
Mar 22 at 9:03
1
1
Thank you, I just wanted to write the same thing.
– Woozar
Mar 22 at 9:03
Thank you, I just wanted to write the same thing.
– Woozar
Mar 22 at 9:03
add a comment |
Try to mention async before your funtion like below I mentioned
async addEmpFn(empData, emp)
empData.name = emp.name;
return await empData.save();
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
1
Cool.. you come up with problem is important...happy coding
– umer sayyed
Mar 22 at 6:58
add a comment |
Try to mention async before your funtion like below I mentioned
async addEmpFn(empData, emp)
empData.name = emp.name;
return await empData.save();
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
1
Cool.. you come up with problem is important...happy coding
– umer sayyed
Mar 22 at 6:58
add a comment |
Try to mention async before your funtion like below I mentioned
async addEmpFn(empData, emp)
empData.name = emp.name;
return await empData.save();
Try to mention async before your funtion like below I mentioned
async addEmpFn(empData, emp)
empData.name = emp.name;
return await empData.save();
edited Mar 22 at 7:23
Tushar Walzade
2,31931935
2,31931935
answered Mar 22 at 6:53
umer sayyedumer sayyed
562
562
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
1
Cool.. you come up with problem is important...happy coding
– umer sayyed
Mar 22 at 6:58
add a comment |
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
1
Cool.. you come up with problem is important...happy coding
– umer sayyed
Mar 22 at 6:58
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
thank you, It's work but too many people give me answer. I've to mark the 1st. I very thank you for your help
– TryHard
Mar 22 at 6:56
1
1
Cool.. you come up with problem is important...happy coding
– umer sayyed
Mar 22 at 6:58
Cool.. you come up with problem is important...happy coding
– umer sayyed
Mar 22 at 6:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294231%2fhow-to-seperate-function-with-await%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown