-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
Use duck-typing over other types of typing #132
Conversation
Codecov Report
@@ Coverage Diff @@
## master #132 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 48 48
Lines 1097 1098 +1
=====================================
+ Hits 1097 1098 +1
Continue to review full report at Codecov.
|
@@ -8,7 +8,7 @@ function After$race(other){ | |||
? other | |||
: isNever(other) | |||
? this | |||
: (other instanceof After || other instanceof RejectAfter) | |||
: typeof other._time === 'number' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good old duck-typing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these the only two occurrences of instanceof
in the project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, no. It's used in some places (like isFuture
) to determine with high performance whether a value is what we want it to be, but these are the only occurrences left where there are no or conditions for the value to be identified as such.
function Never(){} | ||
function Never(){ | ||
this._isNever = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I'm setting it in the constructor, rather than on the prototype, is that it will cause inspect
to provide slightly more insightful output (Future { _isNever: true }
vs Future {}
).
* #128 The performance of transforming Futures has improved significantly. * #131 Future.parallel has been made stack-safe. * #131 Future.parallel now guarantees execution order. * #132 Improve version interoperability. Note that 6.3.x futures will not be compatible with 6.2.x Futures, so when upgrading, make sure to upgrade all producers of Future instances. To avoid having to do this with future releases, I recommend setting Fluture as a devDependency if you are maintaining a library which exposes Future instances to its users.
This will allow Futures of incompatible versions, Futures spawned in other runtime-context (
vm.run*
), or even "custom made" Futures to be consumed by this function.