forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLazyAction.cs
More file actions
32 lines (28 loc) · 1.07 KB
/
LazyAction.cs
File metadata and controls
32 lines (28 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
namespace System.Web.WebPages.ApplicationParts
{
internal class LazyAction
{
private Lazy<object> _lazyAction;
public LazyAction(Action action)
{
Debug.Assert(action != null, "action should not be null");
// Setup the lazy object to run our action and just return null
// since we don't care about the value
_lazyAction = new Lazy<object>(() =>
{
action();
return null;
});
}
public object EnsurePerformed()
{
// REVIEW: This isn't used we're just exploiting the use of Lazy<T> to execute
// our action once in a thread safe way
// It would be nice if the framework had Unit (i.e a better void type so we could type Func<Unit> -> Action)
return _lazyAction.Value;
}
}
}