Welcome to MSDN Blogs Sign in | Join | Help

jaredpar's WebLog

Code, rants and ramblings of a programmer.

Syndication

News

Now Reading

Expert F#

What's a better book to read when learning F#?

Essential WPF

Thus far the best book I've read on WPF. Gets right down to working with WPF and the goals/history.

Purely Functional Data Structures

Reading this book makes me feel like I'm back in college. It will really get your mind going and is best read with a whiteboard handy.

Blog Roll

Eric Lippert
Dustin Campbell
Jon Skeet
Coding Horror
Brian McNamara
Brian Bondy
Hub FS
Full List

Building a Future which returns no Value

In addition to Future<T> there is also the concept of Futures that don't return any values.  Instead the perform the operation and return.  Because there is no additional data to pass between the threads building an Empty Future is fairly straight forward.

The biggest decision is how to declare it.  EmptyFuture exposes no new accessible methods or properties above what Future already exposes.  If a class doesn't provide any additional behavior is there any reason to expose it?  In this case I think not.  Therefore it will be declared as a private inner class of Future

Yes this makes it impossible to directly create from a user perspective.  You could also make a good argument that creation is new behavior and therefore EmptyFuture should be exposed.  However for Future's, as with other generic classes, I prefer static factory methods for creation.  It allows the user to take advantage of type inference as much as possible.

        private class EmptyFuture : Future
        {
            private Action m_action;

            internal EmptyFuture(Action action)
            {
                m_action = action;
            }

            protected override void RunCore()
            {
                m_action();
            }

        }
Next we'll go over the creation of the factory methods to create this and Future<T>. 

Published Monday, February 18, 2008 4:15 PM by Jared Parsons

Filed under: , , ,

Comments

# MSDN Blog Postings &raquo; Building a Future which returns no Value @ Monday, February 18, 2008 5:06 PM

PingBack from http://msdnrss.thecoderblogs.com/2008/02/18/building-a-future-which-returns-no-value/

MSDN Blog Postings » Building a Future which returns no Value

New Comments to this post are disabled
Page view tracker