Thursday, July 20, 2017

TinyPubSub makeover - arguments and new super hero publish features

I finally got around to give TinyPubSub a well deserved make over by adding some features that have been requested for a while. The toughest part is to keep it Tiny and not add to much bells and whistles to it.

I also got some great help from my friend Daniel Hindrikes to set up a devops flow that will help me manage pull requests and nuget-package publishing.

The features added to this version are;

  • Publish with arguments
  • Publish using fire-and-forget (with or without argument)
  • Publish async (with or without argument)

Publish with argument


You can now subscribe and pass an argument of the type Action<string>:

  TinyPubSub.Subscribe("test", (x) => Log.WriteString(x));

And publish it by simply adding another argument:

  TinyPubSub.Publish("test""duck");

In order to keep it tiny we only allow for a single string argument at the moment. We did explore a whole bunch of alternatives, including generics and dynamic objects and stuff but we settled for this at the moment.

Publish using fire and forget (PublishAsTask)


Using a simple Publish in TinyPubSub is synchronous and will stop the execution flow until all the subscribers have executed their code. We've now added a way to publish events fire-and-forget style.

  TinyPubSub.PublishAsTask("test""duck");

Publish async


And the last way is to simply publish async. Works as expected.

  await TinyPubSub.PublishAsync("test""duck");

Resources

2 comments:

  1. Mobdro is a free app that allows us to find and watch video streams and online TV
    on our mobile devices such as Android tablet or smartphone mobdro for kodi

    ReplyDelete
  2. Sony PS3 Emulator is an Android emulator that simulates the Sony Play Station games to the Android phone Playstation 3 emulator

    ReplyDelete