Skip to content

Commit

Permalink
Merge pull request #1 from kirkshoop/rxcpp2.0
Browse files Browse the repository at this point in the history
upgraded to use rxcpp 2.0.0
  • Loading branch information
d-led committed Jun 25, 2014
2 parents c49fd5d + 4c338ca commit 712a54a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ticker/packages.config
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="rxcpp" version="1.0.2" targetFramework="Native" />
<package id="rxcpp" version="2.0.0" targetFramework="Native" />
</packages>
45 changes: 26 additions & 19 deletions ticker/ticker.cpp
Expand Up @@ -2,7 +2,7 @@

#include "frequency_meter.h"
#include "active_ticker.h"
#include <cpprx/rx.hpp>
#include <rxcpp/rx.hpp>
#include <chrono>

namespace {
Expand Down Expand Up @@ -37,36 +37,43 @@ namespace {

void rxcpp_example() {
FrequencyMeter FM;
auto scheduler = std::make_shared<rxcpp::EventLoopScheduler>();
auto measure = rxcpp::Interval(std::chrono::milliseconds(250),scheduler);
auto sleep = [&scheduler](int milliseconds) {
//rxcpp::from(rxcpp::Interval(std::chrono::milliseconds(milliseconds), scheduler))
// .take(1)
// .for_each([](int){});

//concurrency::wait(milliseconds);
std::atomic<long> pending(2);

// schedule everything on the same event loop thread.
auto scheduler = rxcpp::schedulers::make_same_worker(rxcpp::schedulers::make_event_loop().create_worker());
auto coordination = rxcpp::identity_one_worker(scheduler);

auto measure = rxcpp::observable<>::interval(scheduler.now() + std::chrono::milliseconds(250), std::chrono::milliseconds(250), coordination);
auto sleep = [&scheduler](int milliseconds) {
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
};

auto measure_subscription = rxcpp::from(measure)
auto measure_subscription = measure
.subscribe([&FM](int val) {
std::cout << FM.Hz() << std::endl;
});

auto ticker = rxcpp::Interval(std::chrono::milliseconds(500), scheduler);
rxcpp::from(ticker)
auto ticker = rxcpp::observable<>::interval(scheduler.now() + std::chrono::milliseconds(500), std::chrono::milliseconds(500), coordination);
ticker
.take(10)
.subscribe([](int val) {
std::cout << "tick " << val << std::endl;
});


sleep(2000);
std::cout << "Canceling measurement ..." << std::endl;
measure_subscription.Dispose(); // cancel measurement

sleep(6000); // wait for ticker to finish
},[&](){
--pending; // take completed the ticker
});

// schedule the cout on the same worker to keep it from merging with the other cout calls.
scheduler.create_worker().schedule(scheduler.now() + std::chrono::seconds(2),
[&](const rxcpp::schedulers::schedulable&) {
std::cout << "Canceling measurement ..." << std::endl;
measure_subscription.unsubscribe(); // cancel measurement
--pending; // signal measurement canceled
});

while (pending > 0) {
sleep(1000); // wait for ticker and measure to finish
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions ticker/ticker.vcxproj
Expand Up @@ -39,7 +39,7 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros">
<NuGetPackageImportStamp>5fc5653d</NuGetPackageImportStamp>
<NuGetPackageImportStamp>a8c8fb0b</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
Expand Down Expand Up @@ -95,12 +95,12 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\rxcpp.1.0.2\build\native\rxcpp.targets" Condition="Exists('..\packages\rxcpp.1.0.2\build\native\rxcpp.targets')" />
<Import Project="..\packages\rxcpp.2.0.0\build\native\rxcpp.targets" Condition="Exists('..\packages\rxcpp.2.0.0\build\native\rxcpp.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\rxcpp.1.0.2\build\native\rxcpp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\rxcpp.1.0.2\build\native\rxcpp.targets'))" />
<Error Condition="!Exists('..\packages\rxcpp.2.0.0\build\native\rxcpp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\rxcpp.2.0.0\build\native\rxcpp.targets'))" />
</Target>
</Project>

0 comments on commit 712a54a

Please sign in to comment.