A Timely Post – Introducing Palmer and TempusReader

I may have found the Peanut Butter to my Jelly. Maybe not, but I accidentally stumbled upon a project called Palmer. This library lets one define an amount of time to do some sort of activity. Maybe a call that fails frequently, so you want to ping it many times before just giving up. I’m not using it in anything currently, but I’d like to some day.

I noticed that it uses some TimeSpans and I’ve been meaning to incorporate my pet project TempusReader into something of use. I combined the two and they worked just great together! I set up a tiny example like this, just to get going with them:

class Program
    private static int attempts = 0;

    static void Main(string[] args)
        Retry.On<Exception>().For("2.5 seconds".InTime()).With(context =>

    public static string SendRequest()
        Console.WriteLine("attempt #{0}", attempts);
        throw new Exception("Oh snap!");

Obviously the example isn’t real world, but you get the point. The code is actually all Palmer, the only part that is TempusReader is the .InTime() extension method. Alternatively, I could have used other methods to specify the TimeSpan:

new Time("1 hr, 5 mins and 8 seconds")
"50 milliseconds".InTime()

This takes a string and converts it to a TempusReader.Time object, which can be implicitly cast to a TimeSpan for use in the .For() method.

Both these projects are on NuGet (the current version of Palmer was giving me issues):

Install-Package Palmer -Version 0.1.4723.40614

Install-Package TempusReader

Visit the GitHub pages for both Palmer and TempusReader to learn more about how to use them!

About Chris Missal

Oh hey, I'm a Senior Consultant for Headspring in Austin, TX. I've been working in software professionally since 2006 and I really, really love it. I'm mostly in the Microsoft world, but enjoy building computer things of all sorts (to be vague). When I'm not slinging code, I'm probably out and about slinging discs, bowling balls, or good beer with great friends.
This entry was posted in .NET, C#, Open Source and tagged , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Jeff Hamlin

    Love this example, thanks!!

  • Daniel

    In 2010 I did something rather similar:
    [Test]public void TestFullExpression(){ string s = “13y4M23d5h10m43s”; DateExpression dp = new DateExpression( s ); Assert.That( dp.Years, Is.EqualTo( 13 ) ); Assert.That( dp.Months, Is.EqualTo( 4 ) ); Assert.That( dp.Days, Is.EqualTo( 23 ) ); Assert.That( dp.Hours, Is.EqualTo( 5 ) ); Assert.That( dp.Minutes, Is.EqualTo( 10 ) ); Assert.That( dp.Seconds, Is.EqualTo( 43 ) );}