Skip to content

Commit

Permalink
Make period nullable and clarify documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Aug 6, 2024
1 parent 2295035 commit 8582642
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions Bonsai.Core/Reactive/Timer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public class Timer : Source<long>
public TimeSpan DueTime { get; set; }

/// <summary>
/// Gets or sets the period to produce subsequent values. If this value is equal
/// to <see cref="TimeSpan.Zero"/> the timer will recur as fast as possible.
/// Gets or sets the period to produce subsequent values. If this value is not specified
/// or equal to <see cref="TimeSpan.Zero"/> the timer will only fire once.
/// </summary>
[XmlIgnore]
[Description("The period to produce subsequent values. If this value is equal to zero the timer will recur as fast as possible.")]
public TimeSpan Period { get; set; }
[Description("The period to produce subsequent values. If this value is not specified or equal to zero the timer will only fire once.")]
public TimeSpan? Period { get; set; }

/// <summary>
/// Gets or sets an XML representation of the due time for serialization.
Expand All @@ -53,8 +53,8 @@ public string DueTimeXml
[EditorBrowsable(EditorBrowsableState.Never)]
public string PeriodXml
{
get { return XmlConvert.ToString(Period); }
set { Period = XmlConvert.ToTimeSpan(value); }
get { return Period > TimeSpan.Zero ? XmlConvert.ToString(Period.GetValueOrDefault()) : null; }
set { Period = string.IsNullOrEmpty(value) ? null : XmlConvert.ToTimeSpan(value); }
}

/// <summary>
Expand All @@ -69,7 +69,7 @@ public override IObservable<long> Generate()
{
var period = Period;
return period > TimeSpan.Zero
? Observable.Timer(DueTime, period)
? Observable.Timer(DueTime, period.GetValueOrDefault())
: Observable.Timer(DueTime);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Bonsai.Shaders/Timer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class Timer : Source<long>

/// <summary>
/// Gets or sets the period to produce subsequent values. If this value
/// is undefined or equal to zero the timer will only fire once.
/// is not specified or equal to zero the timer will only fire once.
/// </summary>
[XmlIgnore]
[Description("The period to produce subsequent values. If this value is equal to zero the timer will recur as fast as possible.")]
[Description("The period to produce subsequent values. If this value is not specified or equal to zero the timer will only fire once.")]
public TimeSpan? Period { get; set; }

/// <summary>
Expand Down

0 comments on commit 8582642

Please sign in to comment.