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

Promise.delay should allow numeric values that are not strictly integers #66

Closed
benjamingr opened this issue Jan 13, 2014 · 2 comments
Closed

Comments

@benjamingr
Copy link
Collaborator

For compatibility with setTimeout both in browsers and in Node and with other promises library like Q and the Deferred object in the jQuery library I propose:

    Promise.delay(someValue);

To work with numbers that are not integers the same way browsers, other libraries and node would.

This would require changing:

       if ((ms | 0) !== ms || ms < 0) {
            return apiRejection("expecting a positive integer");
        } 

To

       if (typeof ms !== "number") {
            return apiRejection("expecting a number");
        }

For maintaining type safety but making interop with code that does delay(100*Math.random()) for example easier.

@Canop
Copy link
Contributor

Canop commented Jan 13, 2014

👍 The same rules than the ones of setTimeout should probably apply

Apply the ToNumber() abstract operation to timeout, and let timeout be the result. [ECMA262]
If timeout is an Infinity value, a Not-a-Number (NaN) value, or negative, let timeout be zero.

@domenic
Copy link

domenic commented Jan 13, 2014

+1 to @Canop. Parameter validation in ECMAScript is an antipattern; coercion is preferred.

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

No branches or pull requests

3 participants