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

Fixed Sleeping Action #236

Merged
merged 2 commits into from
Apr 18, 2013
Merged

Conversation

mairbek
Copy link
Contributor

@mairbek mairbek commented Apr 17, 2013

Sleeping action wasn't working correctly.

@cloudbees-pull-request-builder

RxJava-pull-requests #95 SUCCESS
This pull request looks good

@@ -29,14 +29,18 @@
public SleepingAction(Func0<Subscription> underlying, Scheduler scheduler, long timespan, TimeUnit timeUnit) {
this.underlying = underlying;
this.scheduler = scheduler;
this.execTime = scheduler.now() + timeUnit.toMillis(timespan);
this.execTime = scheduler.now() + timeUnit.toNanos(timespan);
Copy link
Member

Choose a reason for hiding this comment

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

Is scheduler.now() supposed to be in millis or nanos? If nanos, why exactly? That means it's not actually "time" it's the relative time since the JVM started.

I question if this is correct in AbstractScheduler:

    @Override
    public long now() {
        return System.nanoTime();
    }

Copy link
Member

Choose a reason for hiding this comment

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

We need to make it very clear on the Scheduler interface if it is millis or nanos ... and that should be defined by whether "now" is intended to be absolute or relative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This implementation returns absolute time in nanoseconds. I'll update the javadoc.

Copy link
Member

Choose a reason for hiding this comment

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

It's not absolute time ... the JVM returns nanoseconds since JVM started thus we can't use it to determine absolute time and therefore anything involving absolute time would not work.

http://docs.oracle.com/javase/6/docs/api/java/lang/System.html#nanoTime()

This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary time (perhaps in the future, so values may be negative).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, thanks for pointing out and educating me!
The implementation is still incorrect I'll update this pull request.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks ... the schedulers changes have been merged now as well so this pull request can now correctly work against that.

I'm also in the process of reviewing the ObserveOn changes right now.

Conflicts:
	rxjava-core/src/main/java/rx/concurrency/SleepingAction.java
@cloudbees-pull-request-builder

RxJava-pull-requests #98 SUCCESS
This pull request looks good

benjchristensen added a commit that referenced this pull request Apr 18, 2013
@benjchristensen benjchristensen merged commit 34e097b into ReactiveX:master Apr 18, 2013
rickbw pushed a commit to rickbw/RxJava that referenced this pull request Jan 9, 2014
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.

3 participants