asynchronous

4

Wow!  Now this is a blast from the past, and a very exciting prospect too!  Puppet Master: The Game brings those creepy puppets from the classic cult horror film back to life with asynchronous multiplayer as 3 puppets hunt down one big human.

For those unaware of the awesomeness that is the Puppet Master, check out the Movie trailers here, then go watch the movies (only the first few though, there are 10 of them and the later ones are garbage).

Taking a leaf out of PT‘s book (btw if you have a PS4 go and play that now!), the devs have released an ‘interactive trailer’ which allows you to control Blade - the most iconic of the Puppets.  You get to explore the Masters Workshop, then round up all the other puppets so that they can do what they do best (kill humans).  

If the 3 puppets Vs 1 human asynchronous multiplayer in Puppet Master: The Game ends up being half as good as it sounds it’s going to be a corker.  Things are definitely off to a good start with the Interactive Trailer, which looks, sounds, feels and plays like an authentic extension/recreation of the films.  The Master would be proud of this creation.

Read more & download the Free ‘Interactive Trailer’

greenarraychips.com
Green Array

GreenArray is putting 144 asynchronous microcpus on a single piece of silicon. They seem to be stuck on explicit message passing rather than implicit dataflow. They’re also using imperative Forth, rather than a perhaps more elegant functional approach.

The microcpus are detailed in this design document. It’s stack based, with application stored either in RAM or ROM.

Publish and Subscribe (Pub/Sub) Messaging Pattern

With the pub/sub messaging pattern, the receivers of messages have subscribed to a distribution object. A sender posts messages to this published distribution object, rather than individually addressing message recipients. Usually recipients can subscribe and unsubscribe as needed.

By decoupling publishers and subscribers, a simple, dynamic, asynchronous messaging system can be implemented to enable data exchange among distributed programs. Pub/sub is often a component of message-oriented middleware systems. These systems typically add a variety of message reliability features, along with the ability to specify which programs can send messages through the distribution object, and which programs can subscribe to it.

ASP.NET MVC 4 Developer preview

Microsoft har nylig frigitt ASP.NET MVC 4 i developer preview. Du kan ta en titt på innholdet her http://www.asp.net/whitepapers/mvc4-release-notes.

Mest spennende er den forbedrede støtte for asynkrone action methods. Eksempel fra release notes:

public async Task<ActionResult> Index(string city) {
    var newsService = new NewsService();
    var sportsService = new SportsService();

    return View("Common",
        new PortalViewModel {
        NewsHeadlines = await newsService.GetHeadlinesAsync(),
        SportsScores = await sportsService.GetScoresAsync()
    });
}

Hvis du vil prøve kan du laste ned MVC 4 her

nachbaur.com
Using GCD and Blocks Effectively

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    NSURL *url = [NSURL URLWithString:@"http://bit.ly/nUX01h"];
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    [NSURLConnection sendAsynchronousRequest:req
                                       queue:[NSOperationQueue currentQueue]
                           completionHandler:
     ^(NSURLResponse *res, NSData *data, NSError *err) {
         // Convert the data to a UIImage
         UIImage *image = [UIImage imageWithData:data];
           
         // Scale the image
         UIImage *thumbImage = nil;
         CGSize newSize = CGSizeMake(90, (90 / image.size.width) * image.size.height);
         UIGraphicsBeginImageContext(newSize);
         [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
         thumbImage = UIGraphicsGetImageFromCurrentImageContext();
         UIGraphicsEndImageContext();
           
         dispatch_async(dispatch_get_main_queue(), ^{
             self.imageView.image = thumbImage;
         });
     }];
});

Issues With Iterated Asynchronous Calls In JavaScript

JavaScript preserves the outside scope so that inner scopes can access variables in it. This is usually very convenient, but can lead to wierd errors if you are not careful. This is common when iterating over asynchronous call:

var makeCallsWith = function(animals) {
    for (var i = 0; i < 3; i += 1) {
        // This represents the async nature of an API call
        setTimeout(function() {
            console.log(animals[i]);
        }, 100);
    }
};

makeCallsWith(['dog', 'cat', 'horse']);
// undefined\nundefined\nundefined

This happens because the loop finishes before the callback to the async call, represented here by a timeout, is executed. So the value i passed to the loop is i after it has finished executing; 3. In JavaScript, arrays have no explicit size and all unset values are undefined (technically they are not arrays). Hence the undefined.

Solving this is actually very simple, just wrap each call in a function that preserves the correct scope:

var makeCallsWith = function(animals) {
    for (var i = 0; i < 3; i += 1) {
        (function(i) {
            setTimeout(function() {
                console.log(animals[i]);
            }, 100);
        })(i);
    }
};

makeCallsWith(['dog', 'cat', 'horse']);
// dog\nhorse\ncat

This can also be solved by replacing the for loop with forEach which has the same effect as preserving a scope.

Github Location: https://github.com/Jacob-Friesen/obscurejs/blob/master/2015/iteratedAsyncCalls.js

Anyone for Interrupt.app?

Statistics (and hard data) suggest that people somewhat younger than I rarely call each other. Calling somebody is considered somewhere between impolite and downright rude on the social spectrum. That is unless there is a crisis meriting the “talk to me now” request.

Person-to-person communication is moving from synchronous to asynchronous.

The app that we use to make the old-style calls on a smartphone is generally called Phone or phone.app(!). Perhaps were it renamed Interrupt people might be less inclined to use it.

Best Asynchronous Turn Based Multiplayer Games for iPad iOS

This is a collection of my favourite asynchronous turn based multiplayer games for iPad iOS. Asynchronous multiplayer games are ideal for the iPad (all these games are also compatible with the iPhone). Take your turn, then wait for the other person to go. Take your turn wherever, whenever you’re ready.

Word with Friends
Experience for yourself why more than 20 million people are addicted to the word building, triple score seeking, chat bubble sending goodness of Words With Friends.


Chess with Friends
Play chess with your friends and family online!


Disc Drivin’ HD
Race against your friends at your own pace with the swipe of your finger. Use awesome powers and avoid hazards on beautiful tracks with full 3D physics!


Depict
Depict is an online multiplayer drawing game you can play with friends and strangers from around the world!


Dominion HD
Dominion HD is a modern take on the classic world domination game of strategy, risk and conquest. Players take turns building armies and seizing territory from their opponents.

Notes on Dojo: Asynchronous Module Definition (AMD)

Tested on: Dojo 1.7.1

From version 1.6, the Dojo team started the refactoring of Dojo toolkit in order to make it compliant with the CommonJS AMD API. AMD allows to create more efficient scripts, to use different toolkits in the same web application avoiding conflicts and much more. In version 1.7, the refactoring has been completed and this release is also the base to start the migration to Dojo 2.0.

In this post, I explain how to migrate old code to the new style exploiting AMD module format.

Configuration

First of all we have to configure Dojo in order to use asynchronous features.

<script type="text/javascript">
dojoConfig = {
  baseUrl: "js",
  isDebug: true,
  parseOnLoad: false,
  // enables AMD loader
  async: true,
  // modulePaths parameter is deprecated
  packages: [ 
    {
      "name": "dojo",
      "location": "dojo"
    },
    {
      "name": "dijit",
      "location": "dijit"
    },
    {
      "name": "foo",
      "location": "info/eliacontini"
    }
  ]
};
</script>
<script type="text/javascript" src="js/dojo/dojo.js"></script>

The above configuration works with the following directories layout.

project/
  css/
  img/
  js/
    dijit/
    dojo/
    dojox/
    info/
      eliacontini/
        FooWidget/
          nls/
            en/
              lang.js
            lang.js
          template/
            FooWidget.html
        FooWidget.js
  index.html

After we configured Dojo, we are able to call our FooWidget and to use it in our web application.

<script type="text/javascript">
  require(["foo/FooWidget"], function(Foo){
    var someVar = new Foo();
    /* ... do something with someVar ... */
  });
</script>

Writing custom widgets

Now we have to adapt our FooWidget to the AMD module format.

define([
  /* dijit/_Widget is deprecated */
  "dijit/_WidgetBase",
  /* dijit._Templated is deprecated and
     will be removed in Dojo 2.0 */
  "dijit/_TemplatedMixin",
  // declare function
  "dojo/_base/declare",
  // load template
  "dojo/text!./FooWidget/template/FooWidget.html",
  // load i18n strings
  "dojo/i18n!./FooWidget/nls/lang"
  ],
  function(_Widget, _Templated, declare, template, i18n){
    return declare("info/eliacontini/FooWidget",
      [_Widget, _Templated],{
      templateString: template,
      _i18n: i18n,
      
      constructor: function(){
        console.log(this.templateString);
        console.log(this._i18n.test);
      }
    });
});

In the template file remember to use HTML5 Data Attributes!

Widgets in Template

If in our template we plan to use other widgets in the declarative way, we have to extend also the dijit/_WidgetsInTemplateMixin class.

define([
  ...
  "dijit/_WidgetsInTemplateMixin",
  ...
  ],
  function(..., _WidgetsInTemplate, ...){
    return declare("info/eliacontini/FooWidget",
      [_Widget, _Templated, _WidgetsInTemplate],{
    ...
    widgetsInTemplate: true,
    ...
  });
});

Internationalization (I18N)

In the default language file, we have to specify the default translation and which are the available translations.

This is the default language file.

define({
  root:
  ({
    "test": "test root"
  }),
  "en": true // English translation available
});

In the en directory the file contains:

define(
  ({
    "test": "test en"
  })
);

That’s all!

Update: 31 Jan 2012 - added the section Widgets in Template
Update: 20 Feb 2012 - dijit._WidgetBase instead of dijit._Widget