Skip to content

Latest commit

 

History

History
70 lines (57 loc) · 1.62 KB

README.md

File metadata and controls

70 lines (57 loc) · 1.62 KB

gearman_dart

The Gearman Protocol (中文) implementation in Dart.

Inspired by java-gearman-service.

The project is underlying development, many facilities have not implemeted yet.

Please feel free to report issue or fork it, thank you!

Example

create a 'reverse' worker:

  var worker = new GearmanWorker();
  var future = worker.addServer();
  
  future..handleException((Exception e) {
    print(e.toString());
    return true;
  })
  ..then((v) {
    worker.canDo("reverse");
    
    worker.onJobAssigned = (AssignedJob job) {
      if (job.funcName == "reverse") {
        var res = reverse(job.data);
        job.sendComplete(res);
      }
    };
    
    worker.onNoJob = worker.preSleep;
    worker.onNoOp = worker.grabJob;
    worker.onComplete = worker.grabJob;
    
    worker.grabJob();
  });

create a 'reverse' client:

  var client= new GearmanClient();
  var future = client.addServer();
  
  future.then((v) {
    // TODO: add timeout and disconnect policy
    submitJob() {
      var submittedJob = client.submitJob("reverse", "hello world".charCodes);
      submittedJob
        ..handleException((e) {
          print(e);
          return true;
        })
        ..then((job) {
          job.onComplete = () {
            print("job completed!");
          };
          job.onData = (data) {
            print(new String.fromCharCodes(data));
          };
      });
    };
    submitJob();
    submitJob();
    submitJob();
  });