Skip to content

Commit

Permalink
Merge pull request #12 from k2snowman69/k2snowman69/badReference
Browse files Browse the repository at this point in the history
Added example for how to clone subscribe responses for async use
  • Loading branch information
k2snowman69 authored Sep 10, 2017
2 parents b12e902 + 456e6f3 commit 3624310
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 24 deletions.
19 changes: 11 additions & 8 deletions Threadily.SampleObjects/Threadily.SampleObjects.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ set LIST=
SETLOCAL EnableDelayedExpansion
for /f %%i in ('dir /b /a /s *.cpp') do set LIST=!LIST! %%i
ECHO Building emscripten... this may take a bit
REM "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -O0 -s NO_EXIT_RUNTIME=1 -s EXCEPTION_DEBUG=1
"C:\Program Files\Emscripten\emscripten\1.35.0\emcc" -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -Oz -s NO_EXIT_RUNTIME=1
REM emcc -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -O0 -s NO_EXIT_RUNTIME=1 -s EXCEPTION_DEBUG=1
emcc -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -Oz -s NO_EXIT_RUNTIME=1
ENDLOCAL
</Command>
</PostBuildEvent>
Expand All @@ -96,8 +96,9 @@ xcopy /s/Y *.h $(OutputPath).
set LIST=
SETLOCAL EnableDelayedExpansion
for /f %%i in ('dir /b /a /s *.cpp') do set LIST=!LIST! %%i
REM IF EXIST "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -O0 -s NO_EXIT_RUNTIME=1 -s EXCEPTION_DEBUG=1
IF EXIST "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -Oz -s NO_EXIT_RUNTIME=1
ECHO Building emscripten... this may take a bit
REM emcc -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -O0 -s NO_EXIT_RUNTIME=1 -s EXCEPTION_DEBUG=1
emcc -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -Oz -s NO_EXIT_RUNTIME=1
ENDLOCAL
</Command>
</PostBuildEvent>
Expand All @@ -107,8 +108,9 @@ xcopy /s/Y *.h $(OutputPath).
set LIST=
SETLOCAL EnableDelayedExpansion
for /f %%i in ('dir /b /a /s *.cpp') do set LIST=!LIST! %%i
REM IF EXIST "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -O0 -s NO_EXIT_RUNTIME=1 -s EXCEPTION_DEBUG=1
IF EXIST "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -Oz -s NO_EXIT_RUNTIME=1
ECHO Building emscripten... this may take a bit
REM emcc -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -O0 -s NO_EXIT_RUNTIME=1 -s EXCEPTION_DEBUG=1
emcc -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -Oz -s NO_EXIT_RUNTIME=1
ENDLOCAL
</Command>
</PostBuildEvent>
Expand All @@ -118,8 +120,9 @@ xcopy /s/Y *.h $(OutputPath).
set LIST=
SETLOCAL EnableDelayedExpansion
for /f %%i in ('dir /b /a /s *.cpp') do set LIST=!LIST! %%i
REM IF EXIST "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -O0 -s NO_EXIT_RUNTIME=1 -s EXCEPTION_DEBUG=1
IF EXIST "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -Oz -s NO_EXIT_RUNTIME=1
ECHO Building emscripten... this may take a bit
REM emcc -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -O0 -s NO_EXIT_RUNTIME=1 -s EXCEPTION_DEBUG=1
emcc -std=c++11 %LIST% -I "$(OutputPath)..\Threadily" -o $(OutputPath)$(TargetName).bc -Oz -s NO_EXIT_RUNTIME=1
ENDLOCAL
</Command>
</PostBuildEvent>
Expand Down
108 changes: 94 additions & 14 deletions Threadily.test.web/AppExampleUnitTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,102 @@ describe('App Example', function () {
});
});
});
it('throw test 1', function () {
var app = new module.AppFactory.getInstance().create();
assert.throws(function () {
app.throwTest1();
}, "throwTest1");
});
it('throw test 2', function () {

it('Create product on business out of scope', function (done) {
var handle = null;

var createProduct = function (newBusiness, productName, onDone) {
handle = newBusiness.isCreateProductPending.subscribe(new module.ISubscribeHandleBoolCallback.implement({
onChange(isPending) {
if (!isPending) {
newBusiness.isCreateProductPending.unsubscribe(handle);
console.log("Create product complete");
onDone();
}
}
}));
console.log("Creating product");
newBusiness.createProductAsync(productName);
}
var createBusiness = function (app, businessName, onDone) {
handle = app.isCreateBusinessPending.subscribe(new module.ISubscribeHandleBoolCallback.implement({
onChange(isPending) {
if (!isPending) {
app.isCreateBusinessPending.unsubscribe(handle);
console.log("Creating Businesss complete");
onDone();
}
}
}));
console.log("Creating Business");
app.createBusinessAsync(businessName);
}

var app = new module.AppFactory.getInstance().create();
assert.throws(function () {
app.throwTest1();
}, "throwTest1");
var handle = app.createdBusiness.subscribe(new module.ISubscribeHandleBusinessCallback.implement({
onChange(newBusiness) {
if (newBusiness != null) {
app.createdBusiness.unsubscribe(handle);
setTimeout(function () {
assert.throws(function () {
newBusiness.createProductAsync("Product");
}, "Expected create product to throw due to newBusiness being out of scope");
done();
}, 100);
}
}
}));
createBusiness(app, "Business", function () { });
});
it('throw test 3', function () {

it('Clone subscription', function (done) {
var handle = null;

var createProduct = function (newBusiness, productName, onDone) {
handle = newBusiness.isCreateProductPending.subscribe(new module.ISubscribeHandleBoolCallback.implement({
onChange(isPending) {
if (!isPending) {
newBusiness.isCreateProductPending.unsubscribe(handle);
console.log("Reading products complete");
onDone();
}
}
}));
console.log("Creating product");
newBusiness.createProductAsync(productName);
}
var createBusiness = function (app, businessName, onDone) {
handle = app.isCreateBusinessPending.subscribe(new module.ISubscribeHandleBoolCallback.implement({
onChange(isPending) {
if (!isPending) {
app.isCreateBusinessPending.unsubscribe(handle);
console.log("Creating Businesss complete");
onDone();
}
}
}));
console.log("Creating Business");
app.createBusinessAsync(businessName);
}

var app = new module.AppFactory.getInstance().create();
assert.throws(function () {
app.throwTest1();
}, "throwTest1");
app.createdBusiness.subscribe(new module.ISubscribeHandleBusinessCallback.implement({
onChange(newBusiness) {
if (newBusiness != null) {
newBusiness = newBusiness.clone();
setTimeout(function () {
createProduct(newBusiness, "Product", function () {
newBusiness.delete();
assert.throws(function () {
newBusiness.createProductAsync("Product after deleted");
}, "Expected create product to throw due to newBusiness being out of scope");
done();
});
}, 100);
}
}
}));
createBusiness(app, "Business", function () {
});
});
});
4 changes: 2 additions & 2 deletions Threadily.test.web/Threadily.test.web.njsproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
cd
echo Building Threadily.SampleObjects.js into this directory
del Threadily.SampleObjects.js*
REM "C:\Program Files\Emscripten\emscripten\1.35.0\emcc" -std=c++11 --bind ..\$(Configuration)\Threadily\Threadily.bc ..\$(Configuration)\Threadily.SampleObjects\Threadily.SampleObjects.bc -o Threadily.SampleObjects.js -O0 -s NO_EXIT_RUNTIME=1 -s EXCEPTION_DEBUG=1
"C:\Program Files\Emscripten\emscripten\1.35.0\emcc" -std=c++11 --bind ..\$(Configuration)\Threadily\Threadily.bc ..\$(Configuration)\Threadily.SampleObjects\Threadily.SampleObjects.bc -o Threadily.SampleObjects.js -Oz -s NO_EXIT_RUNTIME=1
REM emcc -std=c++11 --bind ..\$(Configuration)\Threadily\Threadily.bc ..\$(Configuration)\Threadily.SampleObjects\Threadily.SampleObjects.bc -o Threadily.SampleObjects.js -O0 -s NO_EXIT_RUNTIME=1 -s EXCEPTION_DEBUG=1
emcc -std=c++11 --bind ..\$(Configuration)\Threadily\Threadily.bc ..\$(Configuration)\Threadily.SampleObjects\Threadily.SampleObjects.bc -o Threadily.SampleObjects.js -Oz -s NO_EXIT_RUNTIME=1
</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
Expand Down

0 comments on commit 3624310

Please sign in to comment.