Running with Code Like with scissors, only more dangerous


A Loop for WinJS Promises

Posted by Rob Paveza

I had a co-worker ping me from an internal mailing list recently because he was having trouble reading from a network stream. I dug this out of mothballs from Win8 Consumer Preview:

WinJS.Class.define('Game', function() { /* constructor */ },
    { /* instance prototype */ },
    { /* static members */ 
        LoopWhileTrue: function (context, testCallback, actionReturningPromise, state) {
            /// <summary>Loops an action (that returns a promise) until another callback (that returns a Boolean) indicates that it should no longer continue.</summary>
            return new WinJS.Promise(function (success, error) {
                function evalActContinueLoop() {
                    if (, state)) {
                        var innerPromise =, state);
                        innerPromise.then(evalActContinueLoop, function (e) {
                    else {

This code was used for managing game state in a card-playing game app that I never finished. Usage might look like this:

var gameplay = Game.LoopWhileTrue(game, game.isGameInPlay, game.playHand, game.state);

gameplay’ then became a Promise that:

  • is fulfilled when the entire game completes (all hands have been played or a terminal score is achieved, based on the value returned by calling game.isGameInPlay(state)).
  • results in an error-fulfillment state if an internal call results in an error.
  • iteratively calls game.playHand(game.state), passing in ‘game’ as the this pointer (important in JS) until it is fulfilled (see 1st bullet).
  • if game.playHand completes synchronously, this method could cause a stack overflow. This can be broken with periodic use of setImmediate.

This method can conveniently be used to emulate a for-loop or a while-loop. It doesn't quite as well emulate a do-while-loop because it checks the terminal condition, but you could write a simple adapter method to always return true for the first call to the method.


Modern Dilbert Reader v1.3 is in the Store!

Posted by Rob Paveza

I got the new Modern Dilbert Reader uploaded to the Windows App Store. It now has Favorites support as well as Offline Viewing support.

Favorites list

Offline Viewing settings

Get it and enjoy!!!


Coming Soon: Offline Comic Storage for the Modern Dilbert Reader

Posted by Rob Paveza

Modern Dilbert Reader version 1.3 is in the works and is coming along very well! It's got a couple of bug fixes, but more importantly, it has two new features! The first is that it will support caching comics offline, so you can take them on the plane with you! (Yes, I'm actually planning this for an upcoming trip). The second is a built-in Favorites list. We'll leverage the strip information from the Dilbert Strip Index to provide a great rundown of the strips.

Keep an eye out for it soon! It isn't submitted to the Store yet, but I'm hoping to submit it before going on my trip.

Happy holidays!


Modern Dilbert Reader v1.1 submitted to the Store

Posted by Rob Paveza

My Dilbert app for Windows 8, the Modern Dilbert Reader, just got an update that is pending certification for the Windows Store. This change fixes a bug that a few people have periodically seen where strips lie on top of each other. It also speeds up search.

Best, it uses the higher-quality images available for the main strip display.

I'll note when the new version gets updated, but you can download today's version and the Store app will let you know when the new version is available.


Modern Dilbert Reader is now in the Windows 8 Store

Posted by Rob Paveza

My Dilbert reader app has passed certification and is now in the Windows 8 app store! Check out the info about it on my blog or head directly over to the Windows Store web site.

The "Modern Dilbert Reader" app is not endorsed by my employer. :)