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

timers: give Timeouts a constructor name #5793

Merged
merged 1 commit into from
Mar 21, 2016

Conversation

Fishrock123
Copy link
Contributor

Pull Request check-list

  • Does make -j8 test (UNIX) or vcbuild test nosign (Windows) pass with
    this change (including linting)?
  • Is the commit message formatted according to CONTRIBUTING.md?

Affected core subsystem(s)

timers

Description of change

Refs: #5792

No functional difference, this is for clarity only.

@Fishrock123 Fishrock123 added the timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. label Mar 18, 2016
@cjihrig
Copy link
Contributor

cjihrig commented Mar 18, 2016

LGTM

2 similar comments
@Trott
Copy link
Member

Trott commented Mar 18, 2016

LGTM

@jasnell
Copy link
Member

jasnell commented Mar 19, 2016

LGTM

@jasnell
Copy link
Member

jasnell commented Mar 19, 2016

should be safe for v4, no?

@@ -439,7 +439,7 @@ exports.clearInterval = function(timer) {
};


const Timeout = function(after) {
function Timeout(after) {
Copy link
Member

Choose a reason for hiding this comment

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

Any reason not to make it a class Timeout?

class Timeout {
  constructor(after) {
    this._called = false;
    this._idleTimeout = after;
    this._idlePrev = this;
    this._idleNext = this;
    this._idleStart = null;
    this._onTimeout = null;
    this._repeat = null;
  }
  unref () {
    if (this._handle) {
      this._handle.unref();
    } else if (typeof this._onTimeout === 'function') {
      var now = TimerWrap.now();
      if (!this._idleStart) this._idleStart = now;
      var delay = this._idleStart + this._idleTimeout - now;
      if (delay < 0) delay = 0;

      // Prevent running cb again when unref() is called during the same cb
      if (this._called && !this._repeat) {
        exports.unenroll(this);
        return;
      }

      var handle = reuse(this);

      this._handle = handle || new TimerWrap();
      this._handle.owner = this;
      this._handle[kOnTimeout] = function unrefdHandle() {
        this.owner._onTimeout();
        if (!this.owner._repeat)
          this.owner.close();
      };
      this._handle.start(delay, 0);
      this._handle.domain = this.domain;
      this._handle.unref();
    }
    return this;
  }
  ref() {
    if (this._handle)
      this._handle.ref();
    return this;
  }
  close() {
    this._onTimeout = null;
    if (this._handle) {
      this._handle[kOnTimeout] = null;
      this._handle.close();
    } else {
      exports.unenroll(this);
    }
    return this;
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No gain, more code change.

Copy link
Member

Choose a reason for hiding this comment

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

Well, it modernizes things a little and makes them more explicit. If we want to minimize change why not keep it const Timeout and do const Timeout = function Timeout - by naming the function expression you get the same trace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why even assign it though? It's unnecessary.

Typically we have avoided modernization unless it meant performance increases or was part of some refactor that touched the code a lot anyways.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough - I'm sorry if all these questions annoy you :)

@ChALkeR
Copy link
Member

ChALkeR commented Mar 19, 2016

LGTM

Refs: nodejs#5792
PR-URL: nodejs#5793
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Сковорода Никита Андреевич <[email protected]>
@Fishrock123 Fishrock123 merged commit 4fe02e2 into nodejs:master Mar 21, 2016
@Fishrock123 Fishrock123 mentioned this pull request Mar 21, 2016
2 tasks
Fishrock123 added a commit to Fishrock123/node that referenced this pull request Mar 21, 2016
Fixes: nodejs#5823
Refs: nodejs#5793
PR-URL: nodejs#5825
Reviewed-By: Myles Borins <[email protected]>
Fishrock123 added a commit that referenced this pull request Mar 22, 2016
Refs: #5792
PR-URL: #5793
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Сковорода Никита Андреевич <[email protected]>

Conflicts:
	test/message/timeout_throw.out
Fishrock123 added a commit that referenced this pull request Mar 22, 2016
Fixes: #5823
Refs: #5793
PR-URL: #5825
Reviewed-By: Myles Borins <[email protected]>
Fishrock123 added a commit that referenced this pull request Mar 23, 2016
Notable changes:

* buffer: Now properly throws RangeErrors on out-of-bounds writes (Matt
Loring) #5605
  - This effects write{Float|Double} when the noAssert option is not
used.
* timers:
  - Returned timeout objects now have a Timeout constructor name
(Jeremiah Senkpiel) #5793
  - Performance of Immediate processing is now ~20-40% faster (Brian
White) #4169
* vm: Fixed a contextify regression introduced in v5.9.0 (Ali Ijaz
Sheikh) #5800

PR-URL: #5831
Fishrock123 added a commit that referenced this pull request Mar 23, 2016
Notable changes:

* buffer: Now properly throws RangeErrors on out-of-bounds writes (Matt
Loring) #5605
  - This effects write{Float|Double} when the noAssert option is not
used.
* timers:
  - Returned timeout objects now have a Timeout constructor name
(Jeremiah Senkpiel) #5793
  - Performance of Immediate processing is now ~20-40% faster (Brian
White) #4169
* vm: Fixed a contextify regression introduced in v5.9.0 (Ali Ijaz
Sheikh) #5800

PR-URL: #5831
Fishrock123 added a commit that referenced this pull request Mar 23, 2016
Notable changes:

* buffer: Now properly throws RangeErrors on out-of-bounds writes (Matt
Loring) #5605
  - This effects write{Float|Double} when the noAssert option is not
used.
* timers:
  - Returned timeout objects now have a Timeout constructor name
(Jeremiah Senkpiel) #5793
  - Performance of Immediate processing is now ~20-40% faster (Brian
White) #4169
* vm: Fixed a contextify regression introduced in v5.9.0 (Ali Ijaz
Sheikh) #5800

PR-URL: #5831
Fishrock123 added a commit to Fishrock123/node that referenced this pull request Mar 24, 2016
Notable changes:

* buffer: Now properly throws RangeErrors on out-of-bounds writes (Matt
Loring) nodejs#5605
  - This effects write{Float|Double} when the noAssert option is not
used.
* timers:
  - Returned timeout objects now have a Timeout constructor name
(Jeremiah Senkpiel) nodejs#5793
  - Performance of Immediate processing is now ~20-40% faster (Brian
White) nodejs#4169
* vm: Fixed a contextify regression introduced in v5.9.0 (Ali Ijaz
Sheikh) nodejs#5800

PR-URL: nodejs#5831
@MylesBorins
Copy link
Contributor

@Fishrock123 can you confirm that this is safe and ready for v4?

@MylesBorins
Copy link
Contributor

if this does land we should apply the lint fixes found in #5825

@Fishrock123
Copy link
Contributor Author

@thealphanerd should be safe. It's a sorta-feature, but will only show up in logs I think. It's not even exported, so you can't do instanceof checks with it.

@MylesBorins
Copy link
Contributor

@Fishrock123 I'm going to defer to your judgement here. Please feel free to send a backport PR or change the label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants