Skip to content

Refactor isPromise function #222

Open
tanvirstreame wants to merge 1 commit intokibertoad:mainfrom
tanvirstreame:refactor
Open

Refactor isPromise function #222
tanvirstreame wants to merge 1 commit intokibertoad:mainfrom
tanvirstreame:refactor

Conversation

@tanvirstreame
Copy link
Copy Markdown

@tanvirstreame tanvirstreame commented Mar 19, 2024

Refactor for clean code

Comment thread lib/common/Utils.ts Outdated
@@ -1,3 +1,3 @@
export function isPromise(value: any): value is Promise<any> {
return value && value.then !== undefined ? true : false
return value instanceof Promise;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

what about PromiseLike entities?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point. I want to make this line more understandable. How about I change this to -

export function isPromise(value: any): value is Promise<any> {
  return value?.then instanceof Function;
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

or this -

export function isPromise(value: any): value is Promise<any> {
  return Boolean(value && value.then);
}

@tanvirstreame tanvirstreame force-pushed the refactor branch 3 times, most recently from 30aa0f7 to 05cb555 Compare March 19, 2024 13:28
@tanvirstreame tanvirstreame requested a review from kibertoad March 19, 2024 13:30
@tanvirstreame tanvirstreame changed the title Refactor isPromise function with instanceof Promise Refactor isPromise function Mar 19, 2024
@tanvirstreame tanvirstreame changed the title Refactor isPromise function Refactor isPromise function Mar 19, 2024
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