serverless: Configure all promise returning functions as async functions
Use case description
Paves path to https://github.com/serverless/serverless/issues/7171
Ideally we should use just native promises and async/await syntax. Still refactor of whole code seems as too big and problematic task for single PR, it’s better to divide it into smaller clear tasks.
As a first distinct step I believe it’ll simply be good to configure all promise returning functions as async functions (with no adjustments to its bodies, the internal promise flow should remain configured as-is)
Proposed solution
Search for all functions which return an outcome of any BbPromise* (bluebird), Promise* or x.then() operation, and (1) confirm weather it’s justified that function returns promise. if there are no async calls (with exception to fs sync variants which we should refactor in next step to async) (2a) Reconfigure function so it doesn’t return promises. If it’s otherwise (2b) add async keyword in front of function keyword (that’s all, do not adjust function body content)
To avoid making this PR too problematic to review, nothing more should be covered in PR.
It’s likely this PR will already expose some issues, as Framework has logic parts where promise returning functions are in some scenarios treated as sync and in other as async. All handling like that should be fixed with this PR.
As project covers a lot of files, let’s split this work into multiple PR’s each covering following areas:
- Files put directly into
libandlib/classes -
lib/plugins/aws/customResources(https://github.com/serverless/serverless/pull/8698) -
lib/plugins/aws/deploy(https://github.com/serverless/serverless/pull/8698) - Files put directly into
lib/plugins/aws(https://github.com/serverless/serverless/pull/8871) -
lib/plugins/aws/info(https://github.com/serverless/serverless/pull/8875) -
lib/plugins/aws/invokeLocal(https://github.com/serverless/serverless/pull/8876) -
/lib/plugins/aws/lib(https://github.com/serverless/serverless/pull/8872) -
lib/plugins/aws/package/compile/events/alb,lib/plugins/aws/package/compile/events/lib,lib/plugins/aws/package/compile/events/s3and files put directly intolib/plugins/aws/package/compile/events(https://github.com/serverless/serverless/pull/8873) -
lib/plugins/aws/package/compile/events/websockets(https://github.com/serverless/serverless/pull/8874) -
lib/plugins/aws/package/compile/events/apiGateway(https://github.com/serverless/serverless/pull/8869) - Files put directly into
lib/plugins/aws/package/compile(https://github.com/serverless/serverless/pull/8870) -
lib/plugins/aws/package/liband files put directly intolib/plugins/aws/package(https://github.com/serverless/serverless/pull/8870) -
lib/plugins/aws/remove -
lib/plugins/aws/utils - Files put directly into
lib/plugins(https://github.com/serverless/serverless/pull/8875) -
lib/plugins/create(https://github.com/serverless/serverless/pull/9683) -
lib/plugins/interactiveCli(was addressed with extensive feature refactor) -
lib/plugins/package(https://github.com/serverless/serverless/pull/9644) -
lib/plugins/plugin -
lib/utils(https://github.com/serverless/serverless/pull/9809) -
scripts -
test/integration - Files put directly into following folders:
test,test/unit/lib,test/unit/lib/plugins -
test/unit/lib/classes -
test/unit/lib/plugins/aws/common -
test/unit/lib/plugins/aws/deploy - Files put directly into
test/unit/lib/plugins/aws,test/unit/lib/plugins/aws/package,test/unit/lib/plugins/aws/package/compile -
test/unit/lib/plugins/aws/info -
test/unit/lib/plugins/aws/libandtest/unit/lib/plugins/aws/invokeLocal -
test/unit/lib/plugins/aws/package/compile/events/s3,test/unit/lib/plugins/aws/package/compile/events/albandtest/unit/lib/plugins/aws/package/compile/events/lib -
/test/unit/lib/plugins/aws/package/compile/events/apiGateway - Files put directly into
test/unit/lib/plugins/aws/package/compile/events -
test/unit/lib/plugins/aws/package/compile/events/websockets - Files put directly into
test/unit/lib/plugins/aws/package/compile -
test/unit/lib/plugins/aws/package/liband files put directly intotest/unit/lib/plugins/aws/package -
test/unit/lib/plugins/aws/remove -
test/unit/lib/plugins/aws/utils -
test/unit/lib/plugins/createand files put directly intotest/unit/lib/plugins -
test/unit/lib/plugins/interactiveCli -
test/unit/lib/plugins/package -
test/unit/lib/plugins/plugin -
test/unit/lib/utils -
test/utils
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 34 (23 by maintainers)
Commits related to this issue
- [WIP] Add async to obvious functions w/ promises Initial adding of async. NPM test all still passing. Looking to cleanup and handle async/change calling functions if required resolves:#8368 — committed to It-Is-Jeremy/serverless by deleted user 4 years ago
- Convert eligible functions to async functions Converted functions to async, confirmed no breakage by running npm test. Added todo notes for some functions Resolves:#8368 — committed to It-Is-Jeremy/serverless by deleted user 4 years ago
- adding chai-as-promised #8368 — committed to nyamba/serverless by nyamba 3 years ago
can cross out
test/unit/lib/plugins/interactiveClisince there is no async tests under it@nyamba Yes, looks like it’s the case indeed - we had some extensive refactoring implemented recently for that module so it might’ve changed with that. I’m going to cross it out from the list
Hello @nyamba - totally, we’d be happy to accept PRs for that. The list in the issue should be up-to-date - you can pick one from the list that you like and work on it 👍
@KishorBudhathoki10 great thanks for reaching out to help! Still this one is already being covered by @JeremyScott-IO (note the assignment). Please search other issues with good first issue label (which have no one assigned), and see if you can help with those (?)
Concerning code attachments, please use compare links (e.g. you may create a branch in your fork and send us link to its compare view). Sharing zip archives doesn’t feel safe
Ideally functions/methods which do not involve any async operations (but e.g. simply return
BbPromise.resolve(..)) should be configured as sync (so havereturn BbPromise.resolve(x)replaced withreturn xandreturn BbPromise.reject(e)replaced with withthrow e). Still you may approach situations that making them sync breaks things in a way that more sophisticated refactor is needed, keep such cases async to not overcomplicate this PR (let’s addasynckeyword andTODOcomment explaining future intent of having them sync)Hey, I’d like to take this on!
Just to make sure I understand, don’t modify the functions, aside from changing the method to async. However if after changing these I find problems where calling functions can’t handle the now async method, I should fix these calling functions in this same PR?