Skip to content

Instantly share code, notes, and snippets.

@dfox
Created April 27, 2011 15:30
Show Gist options
  • Select an option

  • Save dfox/944478 to your computer and use it in GitHub Desktop.

Select an option

Save dfox/944478 to your computer and use it in GitHub Desktop.

Revisions

  1. David Fox revised this gist Apr 27, 2011. 1 changed file with 3 additions and 6 deletions.
    9 changes: 3 additions & 6 deletions AsynchronousTask.java
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,7 @@
    package co.cantina.async;
    public interface Callback {
    void completed();
    }

    /**
    * An contrived example of an asynchronous task class.
    *
    * @author David Fox
    */
    public class AsynchronousTask extends Thread {

    private Callback callback;
  2. David Fox revised this gist Apr 27, 2011. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions AsynchronousTask.java
    Original file line number Diff line number Diff line change
    @@ -27,9 +27,6 @@ public void run() {
    callback.completed();
    }

    /**
    * @return the result
    */
    public int getResult() {
    return result;
    }
  3. David Fox created this gist Apr 27, 2011.
    36 changes: 36 additions & 0 deletions AsynchronousTask.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    package co.cantina.async;

    /**
    * An contrived example of an asynchronous task class.
    *
    * @author David Fox
    */
    public class AsynchronousTask extends Thread {

    private Callback callback;
    private int result;

    public AsynchronousTask(final Callback callback){
    this.callback = callback;
    }

    @Override
    public void run() {
    try {
    //Do some "work"
    sleep(5);

    result = 42;
    }
    catch (InterruptedException ex) { }

    callback.completed();
    }

    /**
    * @return the result
    */
    public int getResult() {
    return result;
    }
    }