-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,37 @@ | ||
actor | ||
===== | ||
|
||
A one file java actor library. | ||
A minimal java actor library. | ||
|
||
This is a simplified version of <https://github.com/edescourtis/actor> | ||
package com.benbria.actor; | ||
|
||
public class ActorExample { | ||
public static void main(String[] args) throws InterruptedException { | ||
Actor<String> actor = Actor.createAndStart(new Actor.Behavior<String>() | ||
@Override | ||
public boolean onReceive(Actor<String> self, String msg) { | ||
System.out.println("Got: " + msg); | ||
return !msg.equals("stop"); | ||
} | ||
|
||
@Override | ||
public void exception(Actor<String> self, Exception e) {} | ||
}); | ||
|
||
actor.send("hello"); | ||
actor.send("world"); | ||
Thread.sleep(1000); | ||
actor.send("stop"); | ||
} | ||
} | ||
|
||
Output: | ||
<pre> | ||
Got: hello | ||
Got: world | ||
</pre> | ||
|
||
License | ||
- | ||
|
||
MIT |