Skip to content

Commit

Permalink
Exposed monotonic clock from ITimeProvider as @HCanber recommended in a…
Browse files Browse the repository at this point in the history
  • Loading branch information
kekekeks committed Apr 19, 2015
1 parent b476007 commit e81be8e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/core/Akka/Actor/Scheduler/DateTimeNowTimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ public class DateTimeOffsetNowTimeProvider : ITimeProvider, IDateTimeOffsetNowTi
private DateTimeOffsetNowTimeProvider() { }
public DateTimeOffset Now { get { return DateTimeOffset.UtcNow; } }

public static DateTimeOffsetNowTimeProvider Instance { get { return _instance; } }
public TimeSpan MonotonicClock {get { return Util.MonotonicClock.Elapsed; }}

public TimeSpan HighResMonotonicClock{get { return Util.MonotonicClock.ElapsedHighRes; }}

public static DateTimeOffsetNowTimeProvider Instance { get { return _instance; } }
}
}

2 changes: 2 additions & 0 deletions src/core/Akka/Actor/Scheduler/ITimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface ITimeProvider
/// Gets the scheduler's notion of current time.
/// </summary>
DateTimeOffset Now { get; }
TimeSpan MonotonicClock { get; }
TimeSpan HighResMonotonicClock { get; }
}
}

3 changes: 3 additions & 0 deletions src/core/Akka/Actor/Scheduler/SchedulerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ void IActionScheduler.ScheduleRepeatedly(TimeSpan initialDelay, TimeSpan interva

DateTimeOffset ITimeProvider.Now { get { return TimeNow; } }


protected abstract DateTimeOffset TimeNow { get; }
public abstract TimeSpan MonotonicClock { get; }
public abstract TimeSpan HighResMonotonicClock { get; }

protected abstract void InternalScheduleTellOnce(TimeSpan delay, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable);

Expand Down
2 changes: 2 additions & 0 deletions src/core/Akka/Actor/Scheduler/TaskBasedScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class TaskBasedScheduler : SchedulerBase, IDateTimeOffsetNowTimeProvider
{

protected override DateTimeOffset TimeNow { get { return DateTimeOffset.Now; } }
public override TimeSpan MonotonicClock { get { return Util.MonotonicClock.Elapsed; } }
public override TimeSpan HighResMonotonicClock { get { return Util.MonotonicClock.ElapsedHighRes; } }

protected override void InternalScheduleTellOnce(TimeSpan delay, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable)
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Util/MonotonicClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Akka.Util
{
public static class MonotonicClock
internal static class MonotonicClock
{
private static readonly Stopwatch Stopwatch = Stopwatch.StartNew();
private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
Expand Down

0 comments on commit e81be8e

Please sign in to comment.