TaskQueueStdlib: remove dependency on Event::kForever being int.

While transitioning to TimeDelta, WebRTC and Chromium has a
different idea about what type rtc::Event::kForever is. Code
can't assume rtc::Event::kForever is the same type as timed
wait arguments.

Bug: webrtc:14366
Change-Id: I4783c7de6d567c70b211de9aa9889417f6fafba1
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/272060
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37810}
diff --git a/rtc_base/task_queue_stdlib.cc b/rtc_base/task_queue_stdlib.cc
index 19e7dea..f712cfa 100644
--- a/rtc_base/task_queue_stdlib.cc
+++ b/rtc_base/task_queue_stdlib.cc
@@ -74,7 +74,13 @@
   struct NextTask {
     bool final_task = false;
     absl::AnyInvocable<void() &&> run_task;
-    int64_t sleep_time_ms = rtc::Event::kForever;
+    // TODO(bugs.webrtc.org/14366): While transitioning to TimeDelta, WebRTC and
+    // Chromium has a different idea about what type rtc::Event::kForever is.
+    // Code can't assume rtc::Event::kForever is the same type as timed wait
+    // arguments.
+    // Change `sleep_time_ms` to be explicit type, default value
+    // `rtc::Event::kForever` once transition is complete.
+    absl::optional<int64_t> sleep_time_ms;
   };
 
   static rtc::PlatformThread InitializeThread(TaskQueueStdlib* me,
@@ -246,7 +252,15 @@
       continue;
     }
 
-    flag_notify_.Wait(task.sleep_time_ms);
+    // TODO(bugs.webrtc.org/14366): While transitioning to TimeDelta, WebRTC and
+    // Chromium has a different idea about what type rtc::Event::kForever is.
+    // Code can't assume rtc::Event::kForever is the same type as timed wait
+    // arguments.
+    // Simplify after transitioning is complete.
+    if (task.sleep_time_ms.has_value())
+      flag_notify_.Wait(task.sleep_time_ms.value());
+    else
+      flag_notify_.Wait(rtc::Event::kForever);
   }
 }