Skip to content

Instantly share code, notes, and snippets.

@jonorogers
jonorogers / DataflowExtended.cs
Created July 22, 2019 11:32
Dataflow extended
/// <summary>
/// These extensions provide resilient options for linking to cut down on boilerplate
/// They provide a null link for each real link, meaning that there is a block available which will discard messages
/// This behaivour is only really useful with a predicate; otherwise all blocks will be dropped
/// A default predicate is supplied (this may be dangerous if the caller does not understand the default behaivour?)
/// </summary>
public static class ResilientExtensions {
public static IEnumerable<IDisposable> ResilientLinkTo<TOutput>(this ISourceBlock<TOutput> source, ITargetBlock<TOutput> target) {
var link = source.LinkTo(target, x => x != null);
return GenerateNullLink(source, link);
@turtlemonvh
turtlemonvh / main.js
Last active January 3, 2021 16:37
Angular Messaging
var MyApp = angular.module('MyApp');
MyApp.factory('msgBus', ['$rootScope', function($rootScope) {
var msgBus = {};
msgBus.emitMsg = function(msg, data) {
data = data || {};
$rootScope.$emit(msg, data);
};
msgBus.onMsg = function(msg, func, scope) {
var unbind = $rootScope.$on(msg, func);
if (scope) {
@leandrosilva
leandrosilva / Client.cs
Created October 31, 2010 02:54
Asynchronous Client/Server Socket Example with C# (from MSDN library)
// Asynchronous Client Socket Example
// http://msdn.microsoft.com/en-us/library/bew39x2a.aspx
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;
// State object for receiving data from remote device.