Skip to content

Instantly share code, notes, and snippets.

View Horusiath's full-sized avatar

Bartosz Sypytkowski Horusiath

View GitHub Profile
public class ModulesActor : ReceiveActor, IUnboundedStash
{
private Dictionary<string, Tuple<Props, ModuleState>> _moduleRecipes;
public Stash Stash { get; set; }
public ModulesActor()
{
Ready();
}
@Horusiath
Horusiath / AsyncVal.fs
Created August 30, 2016 09:39
AsyncVals - uniform API for working with values and F# Async computations
namespace FSharp.Data.GraphQL
open System
[<Struct>]
type AsyncVal<'T> =
val Value : 'T
val Async : Async<'T>
new (value: 'T) = { Value = value; Async = Unchecked.defaultof<Async<'T>> }
new (async: Async<'T>) = { Value = Unchecked.defaultof<'T>; Async = async }
public class MyActor : ReceiveActor
{
public MyActor()
{
Receive<Debug>(e => Log(e.ToString()));
Receive<Info>(e => Log(e.ToString()));
Receive<Warning>(e => Log(e.ToString()));
Receive<Error>(e => Log(e.ToString()));
Receive<InitializeLogger>(_ => Sender.Tell(new LoggerInitialized()));
}
@Horusiath
Horusiath / Example.cs
Last active March 29, 2022 09:38
Typed actor refs snipped for Akka.NET
using System;
namespace Akka.Testing
{
public interface IMyMessage { }
public sealed class MessageA : IMyMessage { }
public sealed class MessageB : IMyMessage { }
public class MyActor : Actor<IMyMessage>
{
@Horusiath
Horusiath / h.ts
Created October 21, 2016 15:23
HLists and HMaps in typescript
// HList
class HList { }
class HNil extends HList {
static readonly instance = new HNil();
private constructor() {
super();
}
}
class HCons<Value, Next extends HList> extends HList {
[WARNING][22.10.2016 20:37:42][Thread 0001][ActorSystem(TestRunnerLogging)] NewtonSoftJsonSerializer has been detected as a default serializer. It will be obsoleted in Akka.NET starting from version 1.5 in the favor of Wire (for more info visit: http://getakka.net/docs/Serialization#how-to-setup-wire-as-default-serializer ). If you want to suppress this message set HOCON `akka.suppress-json-serializer-warning` config flag to on.
[INFO][22.10.2016 20:37:42][Thread 0006][akka://TestRunnerLogging/deadLetters] Message Bound from akka://TestRunnerLogging/system/IO-TCP/selectors/$a/0 to akka://TestRunnerLogging/deadLetters was not delivered. 1 dead letters encountered.
[RUNNER][22.10.2016 20:37:44][INFO][Akka.MultiNodeTestRunner.Shared]: Starting test Spec
[RUNNER][20:37]: Beginning spec Akka.Cluster.Tests.MultiNode.MemberWeaklyUpMultiNode.Spec on 5 nodes
[RUNNER][22.10.2016 20:37:44][INFO][Akka.MultiNodeTestRunner.Shared]: Started node 1 on pid 5396
[RUNNER][22.10.2016 20:37:44][INFO][Akka
const withCommunities = graphql(gql`
query CommunitiesQuery($offset: Int!, $limit: Int!) {
viewer {
communities(offset: $offset, limit: $limit) {
totalCount,
elements {
id
...communityInfo
}
}
@Horusiath
Horusiath / example.fs
Created November 4, 2016 08:10
Free like a monad
type Distance = float
type Angle = float
type PenColor = string
type TurtleProgram =
// (input params) (response)
| Stop
| Move of Distance * TurtleProgram
| Turn of Angle * TurtleProgram
| PenUp of (* none *) TurtleProgram
@Horusiath
Horusiath / Program.cs
Created November 9, 2016 08:19
Merging two event streams from two persistent actors
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Persistence.Query;
using Akka.Persistence.Query.Sql;
using Akka.Streams;
using Akka.Streams.Dsl;
@Horusiath
Horusiath / example.cs
Last active April 17, 2022 10:27
Generic persistent gateway for Akka.NET at-least-once-delivery semantics
// Delivery mechanism looks like this - if sender wants to reliably deliver payload to recipient
// using at-least-once delivery semantics, it sends that payload wrapped to Messenger actor, which
// is responsible for the persistence and redelivery:
//
// +--------+ +-----------+ +-----------+
// | |--(DeliverOrder<T>)-->| |--(Delivery<T>:1)-->| |
// | | | | /* 2nd attempt */ | |
// | Sender | | Messenger |--(Delivery<T>:2)-->| Recipient |
// | | | | | |
// | | | |<----(Confirm:2)----| |