Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated readme

  • Loading branch information...
commit 32be149ec5790510a697ec707defd21716316a94 1 parent 22748fe
andris9 authored
View
12 examples/client.js
@@ -1,18 +1,16 @@
var Gearman = require("../lib/gearman"),
- gearman = new Gearman("pangalink.net");
+ gearman = new Gearman(); // defaults to localhost
-var job = gearman.submitJob("reverse", "test");
+var job = gearman.submitJob("reverse", "test string");
job.on("error", function(err){
console.log("ERROR: ", err.message || err);
});
-job.on("data", function(chunk){
- if(chunk){
- console.log(chunk.toString());
- }
+job.on("data", function(reversed){
+ console.log(reversed.toString());
});
job.on("end", function(){
console.log("Ready!");
-});
+});
View
2  examples/streamClient.js
@@ -1,6 +1,6 @@
var Gearman = require("../lib/gearman"),
fs = require("fs"),
- gearman = new Gearman("pangalink.net");
+ gearman = new Gearman(); // defaults to localhost
var job = gearman.submitJob("stream", null),
output = fs.createWriteStream(__dirname+"/../../wordlist.txt.copy");
View
2  examples/streamWorker.js
@@ -1,7 +1,7 @@
var Gearman = require("../lib/gearman"),
fs = require("fs");
-var gearman = new Gearman("pangalink.net",0,1);
+var gearman = new Gearman(); // defaults to localhost
var filepath = __dirname+"/../../wordlist.txt";
View
24 examples/worker.js
@@ -1,18 +1,16 @@
var Gearman = require("../lib/gearman"),
- gearman = new Gearman("pangalink.net");
+ gearman = new Gearman(); // defaults to localhost
gearman.registerWorker("reverse", function(payload, worker){
- var str = "", i;
- payload = payload.toString("utf-8");
-
- var counter = 0;
- var timer = setInterval(function(){
- counter++;
- worker.write(counter);
- if(counter>=10){
- worker.error();
- clearInterval(timer);
- }
- }, 1000);
+ if(!payload){
+ worker.error();
+ return;
+ }
+ var reversed = payload.toString("utf-8").split("").reverse().join("");
+ // delay for 1 sec before returning
+ setTimeout(function(){
+ worker.end(reversed);
+ },1000);
+
});
Please sign in to comment.
Something went wrong with that request. Please try again.