Skip to content

3.x Feature: introduce abstract time source for scheduler impl #7154

@SergejIsbrecht

Description

@SergejIsbrecht

Version:
rxjava:3.0.9

Related:
#2943

Precondition:

  • Task with delay scheduled in a Scheduler

Problem:
When the linux kernel wakes up from suspension System.currentTimeMillis will be adjusted on linux x86 OpenJDK. In my case this is bad, because watchdogs/ timer will fire, which they shouldn't. I would like to use a different time-source, but can't, because System.currentTimeMillis is hard-coded.

    public long now(@NonNull TimeUnit unit) {
        return unit.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

Solution:
I would like to introduce a TimeSource interface, which can be set via RxJavaPlugins.

interface TimeSource {
    fun now(unit : TimeUnit) : Long
}

Impl

class NanoSource : TimeSource {
    override fun now(unit: TimeUnit): Long {
        return unit.convert(System.nanoTime(), TimeUnit.NANOSECONDS)
    }
}

In order to not break the current behavior the default TimeSource would still be System.currentTimeMillis().

This idea was pitched by: @artem-zinnatullin in #2943 (comment)

If this is fine request is fine with the community I would try to implement it quickly and create a PR for it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions