Sunday, June 21, 2015

JavaScript Backend: WebWorkers

Generation of async callbacks at transpilation time, from simple blocking logic, into callback-hell.

Async Transform

Using WebWorkers directly requires you define functions for postMessage and onmessage, split your JavaScript into two files, and load libraries in the worker with importScripts. Only low-level-chumps think dealing with these API's directly is a good idea. All these API details are easily abstracted away with syntax inspired from Golang. One of the best things about Golang is the message passing syntax: it makes code more readable, and it prevents a library-war by having this syntax builtin.

result1 = <- mychannel
print result1
result2 = <- mychannel
print result2

The code above gets the result of mychannel that computes something in a WebWorker. This requires waiting for the result, so if written directly by hand in JavaScript, you would need to write a mess of async callbacks. Rusthon automatically translates above into async code, and deals with routing messages to each channel.

__workerpool__.recv( mychannel, function (result1) {
 console.log(result1);
 __workerpool__.recv( mychannel, function (result2) {
  console.log(result2);
 });
});

source code

Channel Select Syntax

Select syntax inspired by Golang, works pretty much the same as Golangs select statement.


for i in range(n):
 print 'trying to select on workers'
 select:
  case res = <- worker1:
   show('case-worker1:' + res)
  case res = <- worker2:
   show('case-worker2:' + res)

example source code

Monday, June 15, 2015

Rusthon Overview


The Old Way

Above is the traditional way software gets developed. It is a slow and complex process, it creates extra work for the coder, because they must manage files, folders, and multiple build tools. This is a headache and it is not secure.

The New Way

Above the new way of software development using Rusthon. Its simple and more secure using only a single markdown file that combines all config files, and source code in multiple languages. Rusthon also includes a powerful Python to Javascript transpiler, so you can do almost everything from Python syntax if you want.

Sunday, May 10, 2015

WebGL CSS3D UI Prototype


I have updated this prototype to work with the latest THREE.js and only use one CSS3DRenderer layer, you can view the live demo on heroku rusthon.herokuapp.com. The shading over the CSS3D windows is done with the bloom fx in THREE.js, some of the stock fx are compatible with RGBA targets, and able to render overtop of the interactive HTML layer.

You can drag and drop Collada (dae) files from your desktop onto the view and they will be loaded and attached to the 3D window. See the source code, here. The prototype works in Google Chrome, Safari, new iphones and androids, but not very well in Firefox see this bug webgl alpha overlay css3d bug