View router_actor.cpp
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
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) |
View generated_network_receive.cpp
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
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); |
View (de)serialization.cpp
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
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 { ... }; |
View actor_ref_cast.cpp
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
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! |
View create_and_send.cpp
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
void main() { | |
auto system = ActorSystem{} | |
auto ref = make_actor<HelloActor>(system, "Greetings"); | |
ref.send("Bob"); | |
ref.send(false); // compile error! | |
} |
View defining_the_actor.cpp
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
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){}; |
View cpp-vs-js-lambda-2.js
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
function addX(x) { | |
return (n) => { | |
return n + x; | |
} | |
} | |
const addFive = addX(5); | |
addFive(10); | |
// returns 15 |
View cpp-vs-js-lambda-1.cc
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
#include <algorithm> | |
#include <functional> | |
#include <vector> | |
int main() { | |
std::function<int(int)> addOne = [](int x) -> int { | |
return x + 1; | |
}; | |
addOne(5); |
View cpp-vs-js-lambda-1.js
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
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] |
View ratelimit.scala
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
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} |