Marcel Zickler 3 роки тому
батько
коміт
17ab63bce8

+ 2 - 0
Assets/Scripts/Logging/AsyncLogFileWriter.cs

@@ -36,6 +36,8 @@ namespace Logging
 
         public async Task WriteDataLines<T>(IEnumerable<IEnumerable<T>> lines)
         {
+            //This method is ultimately called by an Update Method. Unity doesn't await Update
+           
             var sb = new StringBuilder();
             foreach (var l in lines)
             {

+ 6 - 3
Assets/Scripts/Logging/Logging.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Threading.Tasks;
 using UnityEngine;
 
 namespace Logging
@@ -7,8 +8,9 @@ namespace Logging
     {
         public float writeInterval = 1f;
 
-        private float prevLogTimestamp = 0f;
+        private float prevLogTimestamp;
         private FileLogger logger;
+        private Task previousLogUpdateTask = Task.CompletedTask;
 
         private void Awake()
         {
@@ -20,14 +22,15 @@ namespace Logging
             logger = FileLogger.Instance;
         }
 
-        private async void Update()
+        private void Update()
         {
+            if(!previousLogUpdateTask.IsCompleted) return;
             var time = Time.time;
             var dif =  time - prevLogTimestamp;
             if (dif >= writeInterval)
             {
-                await logger.UpdateRegisteredLogs();
                 prevLogTimestamp = time;
+                previousLogUpdateTask = logger.UpdateRegisteredLogs();
             }
         }