Hello how can I write the following code so that there is no race condition if I return inside the get() function it only returns from that function but if I return from the outer function it prematurely returns.
function checkifvalid (userIdPassed) {
// code to be executed
var params43 = {
TableName: 'users',
Key: {
'pid': req.user.iden
}
}
var returnVal = null
docClient.get(params43, function (err43, data43) {
if (err43) {
return res.json({'errasdsd342sd': 'erhf32623hrf'})
} else {
if (data43.Item.useract && data43.Item.curadmin != '0') {
returnVal = true
} else {
returnVal = false
}
}})
if (returnVal !== null) {
return returnVal
}
}