|
| 1 | +// Copyright 2023 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import Foundation |
| 16 | + |
| 17 | +// TODO: Get rid of public's and @objc's once FirebaseAuth.m is in Swift. |
| 18 | + |
| 19 | +/** @class AuthDispatcher |
| 20 | + @brief A utility class used to facilitate scheduling tasks to be executed in the future. |
| 21 | + */ |
| 22 | +@objc(FIRAuthDispatcher) public class AuthDispatcher: NSObject { |
| 23 | + @objc(sharedInstance) public static let shared = AuthDispatcher() |
| 24 | + |
| 25 | + /** @property dispatchAfterImplementation |
| 26 | + @brief Allows custom implementation of dispatchAfterDelay:queue:callback:. |
| 27 | + @remarks Set to nil to restore default implementation. |
| 28 | + */ |
| 29 | + @objc public |
| 30 | + var dispatchAfterImplementation: ((TimeInterval, DispatchQueue, @escaping () -> Void) -> Void)? |
| 31 | + |
| 32 | + /** @fn dispatchAfterDelay:queue:callback: |
| 33 | + @brief Schedules task in the future after a specified delay. |
| 34 | + |
| 35 | + @param delay The delay in seconds after which the task will be scheduled to execute. |
| 36 | + @param queue The dispatch queue on which the task will be submitted. |
| 37 | + @param task The task (block) to be scheduled for future execution. |
| 38 | + */ |
| 39 | + @objc public |
| 40 | + func dispatch(afterDelay delay: TimeInterval, queue: DispatchQueue, task: @escaping () -> Void) { |
| 41 | + if let dispatchAfterImplementation { |
| 42 | + dispatchAfterImplementation(delay, queue, task) |
| 43 | + } else { |
| 44 | + queue.asyncAfter(deadline: DispatchTime.now() + delay, execute: task) |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments