Make published paths thread safe
This commit is contained in:
parent
abab07b8e6
commit
2729418006
12
Ooui/UI.cs
12
Ooui/UI.cs
|
@ -56,7 +56,7 @@ namespace Ooui
|
|||
public static void Publish (string path, Func<Element> elementCtor)
|
||||
{
|
||||
Console.WriteLine ($"PUBLISH {path}");
|
||||
publishedPaths[path] = elementCtor;
|
||||
lock (publishedPaths) publishedPaths[path] = elementCtor;
|
||||
Start ();
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,10 @@ namespace Ooui
|
|||
s.Write (clientJsBytes, 0, clientJsBytes.Length);
|
||||
}
|
||||
}
|
||||
else if (publishedPaths.TryGetValue (path, out ctor)) {
|
||||
else {
|
||||
var found = false;
|
||||
lock (publishedPaths) found = publishedPaths.TryGetValue (path, out ctor);
|
||||
if (found) {
|
||||
WriteElementHtml (path, response);
|
||||
}
|
||||
else {
|
||||
|
@ -156,6 +159,7 @@ namespace Ooui
|
|||
response.Close ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteElementHtml (string elementPath, HttpListenerResponse response)
|
||||
{
|
||||
|
@ -184,7 +188,9 @@ namespace Ooui
|
|||
var path = url.LocalPath;
|
||||
|
||||
Func<Element> ctor;
|
||||
if (!publishedPaths.TryGetValue (path, out ctor)) {
|
||||
var found = false;
|
||||
lock (publishedPaths) found = publishedPaths.TryGetValue (path, out ctor);
|
||||
if (!found) {
|
||||
listenerContext.Response.StatusCode = 404;
|
||||
listenerContext.Response.Close ();
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue