Skip to content

Instantly share code, notes, and snippets.

@wez
Created October 20, 2009 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wez/213953 to your computer and use it in GitHub Desktop.
Save wez/213953 to your computer and use it in GitHub Desktop.
playing with workers in titanium
var fs = Titanium.Filesystem;
var api = Titanium.API;
api.print("worker starting\n");
var path = fs.getResourcesDirectory() + fs.getSeparator() + 'worker.php';
api.print("PHP code is at " + path + "\n");
if (false) {
onmessage = function(event) {
api.print("worker got an event\n");
var j = Titanium.JSON.stringify(event.message);
api.print("event contents are " + j + "\n");
var res;
try {
res = Titanium.PHP.evaluate(
'text/php', 'workerbits',
"include('" + path + "');\n",
event.message);
} catch (err) {
api.print("Error while evaluating " + err + "\n");
}
api.print("After calling the php worker\n");
api.print("res is " + res + "\n");
};
} else {
var res;
try {
res = Titanium.PHP.evaluate(
'text/php', 'workerbits',
"include('" + path + "');\n",
new Object());
} catch (err) {
api.print("Error while evaluating " + err + "\n");
}
api.print("After calling the php worker\n");
api.print("res is " + res + "\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment