Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the original response in @exec-time #168

Open
wants to merge 3 commits into
base: 2.11.0
Choose a base branch
from

Conversation

masoud-msk
Copy link
Contributor

@masoud-msk masoud-msk commented Sep 30, 2024

This example implies that @execTime decorator doesn't change the method signature:

    @execTime()
    getData(): Promise<DataDto> {
      return this.dataProvider.getData();
    }

But it's not true. This PR is fixing this.

Addressing #171

@masoud-msk
Copy link
Contributor Author

@vlio20 It looks like you should update the CI job.

@vlio20
Copy link
Owner

vlio20 commented Oct 7, 2024

trying...

@vlio20
Copy link
Owner

vlio20 commented Oct 7, 2024

@masoud-msk do you want to try and updated actions/upload-artifact: v1 ?

@masoud-msk
Copy link
Contributor Author

@vlio20 Sorry, I don't have any experience with GitHub Actions!

@@ -1,5 +1,5 @@
export function isPromise(obj: any): obj is Promise<any> {
return !!(obj && obj.then !== undefined);
return !!(obj && typeof obj.then === 'function');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this had to be changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firstly, to exactly reflect the specs.
Secondly, the checked variable was used with await keyword and it doesn't error on a non-Promise but I changed the code to call the .then method on the variable and the runtime throws if it's not a valid Promise. The reason for this change is that I think it's impossible to implement otherwise.

For clarification see this:

const o1 = { then: func => func(42) }
const o2 = { then: 42 }

await o1 // 42
await o1 // { then: 42 }

o1.then(console.log) // 42
o2.then(console.log) // Uncaught TypeError: o2.then is not a function

P.S. Maybe it's better to write test for this utility function.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind to write this utility function as you suggested?

src/exec-time/exec-timify.ts Show resolved Hide resolved
src/exec-time/exec-timify.ts Show resolved Hide resolved
@vlio20
Copy link
Owner

vlio20 commented Nov 2, 2024

@masoud-msk I fixed the CI. I have few questions regarding your PR.

@vlio20 vlio20 changed the base branch from master to 2.11.0 December 6, 2024 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants