balderdashy / balderdashy/sails
Asynchronous actions2 functions are being implemented as type: 'classical' preventing exits.
- Dominant language
- JavaScript
- Stars
- 22.8k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
**Node version**: 12.16.2
**Sails version** _(sails)_: 1.5.0
**ORM hook version** _(sails-hook-orm)_: ^3.0.2
**Sockets hook version** _(sails-hook-sockets)_: ^2.0.1
**Organics hook version** _(sails-hook-organics)_: ^2.2.0
**Grunt hook version** _(sails-hook-grunt)_: ^2.2.0
**Uploads hook version** _(sails-hook-uploads)_: N/A
**DB adapter & version** _(e.g. sails-mysql@5.55.5)_: sails-mongo@2.0.0
**Skipper adapter & version** _(e.g. skipper-s3@5.55.5)_: ^0.9.1
My asynchronous actions/helpers/etc `implementationType` are being set to `classical` implementation when I use an async function. This prevents them from using exits and work arounds have to be used to make them asynchronous.
```
module.exports = {
friendlyName: 'Testing async func',
description: '',
inputs: {
},
exits: {
},
fn: async function (inputs, exits, env) {
console.log(Object.keys(this), this.arguments, inputs, exits, env && Object.keys(env))
return exits.success('ok yep.')
}
};
```
If I use `implementationType: 'analog',` within the actions object, it works just as expected. IE
```
module.exports = {
friendlyName: 'Testing async func',
description: '',
implementationType: 'analog',
inputs: {
},
exits: {
},
fn: async function (inputs, exits, env) {
console.log(Object.keys(this), this.arguments, inputs, exits, env && Object.keys(env))
return exits.success('ok yep.')
}
};
```
Here is synchronous file with async functions...
```
async function asyncTest(inputs, exits) {
console.log(Object.keys(this), this.arguments, inputs, exits, env && Object.keys(env))
// ... await async stuff in here ...
return exits.success('ok yep.')
}
module.exports = {
friendlyName: 'Testing async func',
description: '',
inputs: {
},
exits: {
},
fn: function (inputs, exits, env) {
return asyncTest(inputs, exits)
}
};
```
Where does this get determined? Should I just include the implementationType parameter in all action2 files? There is no documentation on this parameter or why this is happening.
Contributor guide
Research direction
The report names no source file or test. Reproduce the action2 case with an async fn and trace where implementationType is determined, comparing the default behavior with explicit implementationType: 'analog'; done means the behavior is understood and the async action can use exits without a workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100