Skip to content

Commit

Permalink
Updated to Rx4.1.1, fixed memory leak with the IsOpen ReadOnlyReactiv…
Browse files Browse the repository at this point in the history
…eProperty, Seperated into two Elements, IsOpen as a bool and IsOpenObservable as a IObservable bool
  • Loading branch information
ChrisPulman committed Oct 17, 2018
1 parent 2872d8d commit bbf72f1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
8 changes: 7 additions & 1 deletion SerialPortRx/ISerialPortRx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ public interface ISerialPortRx : IDisposable
/// Gets the is open.
/// </summary>
/// <value>The is open.</value>
IReadOnlyReactiveProperty<bool> IsOpen { get; }
bool IsOpen { get; }

/// <summary>
/// Gets the is open observable.
/// </summary>
/// <value>The is open observable.</value>
IObservable<bool> IsOpenObservable { get; }

/// <summary>
/// Gets or sets the parity.
Expand Down
6 changes: 3 additions & 3 deletions SerialPortRx/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

[assembly: AssemblyTitle("SerialPortRx")]
[assembly: AssemblyDescription("An Observable Com port extension of System.IO.Ports.SerialPort")]
[assembly: AssemblyConfiguration(".Net 4.7.1")]
[assembly: AssemblyConfiguration(".Net 4.6.1")]
[assembly: AssemblyCompany("ChrisPulman")]
[assembly: AssemblyProduct("SerialPortRx")]
[assembly: AssemblyCopyright("Copyright © https://github.com/ChrisPulman 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("cda3585b-d3d6-4be4-9a6b-582ab5de0b8f")]
[assembly: AssemblyVersion("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.3.0")]
[assembly: AssemblyFileVersion("1.3.0")]
10 changes: 8 additions & 2 deletions SerialPortRx/SerialPortRx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ public SerialPortRx()
/// <value>The is open.</value>
[Browsable(true)]
[MonitoringDescription("IsOpen")]
public IReadOnlyReactiveProperty<bool> IsOpen => isOpen.ToReadOnlyReactiveProperty();
public bool IsOpen => isOpen.Value;

/// <summary>
/// Gets the is open observable.
/// </summary>
/// <value>The is open observable.</value>
public IObservable<bool> IsOpenObservable => Observable.Create<bool>(obs => isOpen.Subscribe(obs));

/// <summary>
/// Gets or sets the parity.
Expand Down Expand Up @@ -309,7 +315,7 @@ from data in port.ReadExisting()
});
}).OnErrorRetry((Exception ex) => errors.OnNext(ex)).Publish().RefCount();

private IReactiveProperty<bool> isOpen { get; } = new ReactiveProperty<bool>();
internal IReactiveProperty<bool> isOpen { get; } = new ReactiveProperty<bool>();

/// <summary>
/// Closes this instance.
Expand Down
7 changes: 5 additions & 2 deletions SerialPortRx/SerialPortRx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CP.IO.Ports</RootNamespace>
<AssemblyName>SerialPortRx</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand All @@ -35,6 +35,9 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Release\SerialPortRx.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Compile Include="ISerialPortRx.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -58,7 +61,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="RxProperty">
<Version>5.3.0</Version>
<Version>5.3.2</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions SerialPortRx/SerialPortRx.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<copyright>Copyright © $author$ 2018</copyright>
<projectUrl>https://github.com/chrispulman/SerialPortRx</projectUrl>
<dependencies>
<dependency id="RxProperty" version="5.3.0" />
<dependency id="RxProperty" version="5.3.2" />
</dependencies>
</metadata>
<files>
<file src="bin\$configuration$\$id$.pdb" target="lib\net471\" />
<file src="bin\$configuration$\$id$.pdb" target="lib\net461\" />
</files>
</package>
2 changes: 1 addition & 1 deletion SerialPortRx/SerialPortRxMixins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static IObservable<TSource> OnErrorRetry<TSource, TException>(this IObser
/// <returns></returns>
public static IObservable<bool> WhileIsOpen(this SerialPortRx @this, TimeSpan timespan) =>
Observable.Defer(() => Observable.Create<bool>(obs => {
var isOpen = Observable.Interval(timespan).CombineLatest(@this.IsOpen.DistinctUntilChanged(), (a, b) => b).Where(x => x);
var isOpen = Observable.Interval(timespan).CombineLatest(@this.isOpen, (a, b) => b).Where(x => x);
return isOpen.Subscribe(obs);
}));
}
Expand Down

0 comments on commit bbf72f1

Please sign in to comment.