This file contains hidden or 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
template<BehaviorType T> | |
class RoundRobinRouter | |
: public Actor | |
, public T | |
{ | |
const std::vector<actor_ref<T>> m_children; | |
std::vector<actor_ref<T>>::iterator m_it; | |
public: | |
RoundRobinRouter(std::vector<actor_ref<T>> const& actors) |
This file contains hidden or 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
void network_receive(MessageWrapper const& wrapper) { | |
if (wrapper.type_id == get_message_type_id<std::string>()) { | |
this->receive(*dynamic_cast<std::string *>(wrapper.value)); | |
} | |
else if (wrapper.type_id == get_message_type_id<SerializableHello>()) { | |
this->receive(*dynamic_cast<SerializableHello *>(wrapper.value)); | |
} | |
else { | |
// unknown | |
this->send_dead_letters(wrapper); |
This file contains hidden or 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
class SerializabelHello {}; | |
class NonSerializableHello {}; | |
class HelloBehavior: public Behavior { | |
virtual void receive(SerializableHello const& msg) = 0; | |
virtual void receive(NonSerializableHello const& msg) = 0; | |
}; | |
class HelloActor: public Actor, public HelloBehavior { ... }; |
This file contains hidden or 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
auto ref = make_actor<HelloActor>(system, "Greetings"); | |
auto generic_ref = actor_ref_cast<HelloBehavior>(ref); | |
generic_ref.send("Bob"); // still works! | |
generic_ref.send(false); // still an error! |
This file contains hidden or 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
void main() { | |
auto system = ActorSystem{} | |
auto ref = make_actor<HelloActor>(system, "Greetings"); | |
ref.send("Bob"); | |
ref.send(false); // compile error! | |
} |
This file contains hidden or 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
class HelloBehavior: public Behavior { | |
virtual void receive(std::string const& msg) = 0; | |
}; | |
class HelloActor | |
: public Actor | |
, public HelloBehavior { | |
std::string m_greeting; | |
public: | |
HelloActor(std::string const& greeting): m_greeting(greeting){}; |
This file contains hidden or 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
function addX(x) { | |
return (n) => { | |
return n + x; | |
} | |
} | |
const addFive = addX(5); | |
addFive(10); | |
// returns 15 |
This file contains hidden or 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
#include <algorithm> | |
#include <functional> | |
#include <vector> | |
int main() { | |
std::function<int(int)> addOne = [](int x) -> int { | |
return x + 1; | |
}; | |
addOne(5); |
This file contains hidden or 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
const addOne = (x) => x + 1; | |
} | |
addOne(5); | |
// returns 6 | |
// use lambda as a value | |
[1, 2, 3, 4, 5].map(addOne) | |
// returns [2, 3, 4, 5, 6] |
This file contains hidden or 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
package scratchspace | |
import java.time.LocalDateTime | |
import java.util.{Deque, LinkedList} | |
import scala.concurrent.{Future, Promise, TimeoutException} | |
import scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.util.{Failure, Success} | |
import java.util.concurrent.{ScheduledFuture, ScheduledThreadPoolExecutor, TimeUnit} |