Skip to content

Is the setTimeout "delay" argument universally optional? #7

@cowboy

Description

@cowboy

I don't want to unnecessarily complicate the first example, but should the asap = setTimeout; bit be changed like so?

var asap;
var isNode = typeof process !== "undefined" &&
             {}.toString.call(process) === "[object process]";

if (isNode) {
  asap = process.nextTick;
} else if (typeof setImmediate !== "undefined") {
  asap = setImmediate;
} else {
  asap = function(fn) {
    setTimeout(fn, 0);
  };
}

export default asap;

Aside: because setImmediate returns an id value, you'd probably want to wrap it in a function to prevent a value being returned. Well, if you were designing a real API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions