Timer management method and device, computer equipment and storage medium
By generating a global timer management object and managing target timers using preset strategies, the problem of centralized control of timer task management in graphical user interface systems is solved, achieving reasonable resource reclamation and system stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-27
- Publication Date
- 2026-03-10
AI Technical Summary
In graphical user interface systems, existing technologies cannot effectively manage timer tasks centrally, leading to resource waste and memory leaks.
By generating a global timer management object, a target timer corresponding to the target task is created when the graphical user interface starts, and centralized control, status management and resource reclamation are performed based on a preset management strategy, including pausing and destroying timed tasks to adapt to user operations.
It enables centralized control of timer tasks throughout the lifecycle of graphical user interface applications, avoiding resource waste and memory leaks, and ensuring stable system operation.
Smart Images

Figure CN121636097A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of timed task processing technology, and in particular to a timer management method, apparatus, computer device, and storage medium. Background Technology
[0002] In a graphical user interface (GUI) system, if certain business operations have high requirements for data real-time performance, then information will be queried through the interface periodically throughout the entire lifecycle after logging into the GUI page. Alternatively, after performing certain operations, it may be necessary to terminate, pause, or restart the timer function. This involves system-level timer tasks and business timer tasks, making centralized control of these timer tasks particularly important.
[0003] In traditional GUI development, JavaScript provides two native application programming interfaces (APIs) – setInterval() and setTimeout() – to implement scheduled tasks.
[0004] However, traditional technologies have the problem of not being able to centrally manage timers. Summary of the Invention
[0005] Therefore, it is necessary to provide a timer management method, device, computer equipment, and storage medium that can centrally manage timers, addressing the aforementioned technical problems.
[0006] Firstly, this application provides a timer management method, the method comprising:
[0007] When the graphical user interface (GUI) is started, a global timer management object is generated;
[0008] Upon detecting the start of a target task, the global timer management object is invoked to create a target timer corresponding to the target task;
[0009] The target timer is managed based on a preset management strategy.
[0010] In the above timer management method, a global timer management object is generated when the graphical user interface (GUI) is started. When the target task is detected to be started, the global timer management object is called to create the target timer corresponding to the target task. Based on the preset management strategy, the target timer is managed. Through the generated global timer management object, the system can achieve centralized control, state management, component communication, and reasonable resource reclamation of all timer tasks in the system throughout the entire life cycle of the GUI application, thereby realizing centralized management of timers.
[0011] In one embodiment, managing the target timer based on a preset management strategy includes at least one of the following:
[0012] The target timer is controlled to execute a timed task according to a preset period;
[0013] The timed task is controlled based on the operation information of the target task.
[0014] In this embodiment, after creating the target timer corresponding to the target task, and before manually removing the timer task, the created target timer executes the timed task according to a preset period by default. During the execution of the target timer task, if a change in the target task's operation information is detected, the timer task is controlled based on the target task's operation information. This enables centralized control, state management, component communication, and reasonable resource reclamation of all timer tasks within the system throughout the complete lifecycle of the GUI application.
[0015] In one embodiment, controlling the timed task based on the operation information of the target task includes:
[0016] If a switching operation for the target task is detected during the execution of the target timer's scheduled task, then the scheduled task is paused; or,
[0017] If a removal operation is detected for the target task during the execution of the target timer's scheduled task, then the scheduled task is destroyed; or,
[0018] If a switch from another task to the target task is detected, the target timer is controlled to continue executing the timed task according to the preset period.
[0019] In this embodiment, based on the different operation information of the target task during the execution of the timer task, different control methods for the timer task are set. Before the timer task is manually removed, the timer task is executed according to the specified periodic strategy by default. During the execution of the timer task, if the user is detected to manually switch to another window, the default strategy is to pause the timer task, change the timer state to a dormant state, and stop occupying resources. When the user switches back to the current window, all timer tasks continue to execute. When accessing different services, by adding timer tasks, manually removing timer tasks, and listening for switching to other windows, the system can achieve centralized control, state management, component communication, and reasonable resource reclamation of all timer tasks within the system throughout the complete lifecycle of the GUI application.
[0020] In one embodiment, destroying the timed task includes:
[0021] Call the globally unified interface to destroy the scheduled task.
[0022] In this embodiment, by calling the global unified interface to destroy the timer task, memory leaks caused by omissions in clearing can be avoided.
[0023] In one embodiment, the step of invoking the global timer management object to create a target timer corresponding to the target task upon detecting the start of the target task includes:
[0024] Upon detecting the start of a target task, the global timer management object is invoked to create the target timer based on the type of the target task.
[0025] In one embodiment, the method further includes:
[0026] Determine whether the callback function of the target timer returns a Promise object;
[0027] If so, after obtaining the execution result of the previous callback function, start calculating the remaining execution time of the next scheduled task;
[0028] If not, the remaining execution time for the next scheduled task will be calculated after the previous callback function is executed.
[0029] In this embodiment, by determining whether the callback function of the target timer returns a Promise object, if the callback function returns a Promise object, the remaining execution time of the next scheduled task is calculated after obtaining the execution result of the previous callback function. If the callback function does not return a Promise object, the remaining execution time of the next scheduled task is calculated after the execution of the previous callback function. This effectively breaks the problem that setInterval() executes at a fixed time interval regardless of the scenario, and to a certain extent ensures that the system runs more stably.
[0030] Secondly, this application also provides a timer management device, the device comprising:
[0031] The generation module is used to generate a global timer management object when the graphical user interface (GUI) is started.
[0032] A creation module is used to call the global timer management object to create a target timer corresponding to the target task when the target task is detected to have started.
[0033] The management module is used to manage the target timer based on a preset management strategy.
[0034] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0035] When the graphical user interface (GUI) is started, a global timer management object is generated;
[0036] Upon detecting the start of a target task, the global timer management object is invoked to create a target timer corresponding to the target task;
[0037] The target timer is managed based on a preset management strategy.
[0038] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0039] When the graphical user interface (GUI) is started, a global timer management object is generated;
[0040] Upon detecting the start of a target task, the global timer management object is invoked to create a target timer corresponding to the target task;
[0041] The target timer is managed based on a preset management strategy.
[0042] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0043] When the graphical user interface (GUI) is started, a global timer management object is generated;
[0044] Upon detecting the start of a target task, the global timer management object is invoked to create a target timer corresponding to the target task;
[0045] The target timer is managed based on a preset management strategy.
[0046] The aforementioned timer management method, device, computer equipment, and storage medium generate a global timer management object when the graphical user interface (GUI) is started, call the global timer management object when the target task is detected to start, create a target timer corresponding to the target task, and manage the target timer based on a preset management strategy. Through the generated global timer management object, the system can achieve centralized control, status management, component communication, and reasonable resource reclamation of all timer tasks within the system throughout the entire lifecycle of the GUI application, thereby realizing centralized management of timers. Attached Figure Description
[0047] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0048] Figure 1 This is a flowchart illustrating a timer management method in one embodiment;
[0049] Figure 2 This is a schematic diagram illustrating the transition of the timer task state in one embodiment;
[0050] Figure 3 This is a flowchart illustrating the timer management method in another embodiment;
[0051] Figure 4 This is a flowchart illustrating the timer management method in another embodiment;
[0052] Figure 5 This is a structural block diagram of a timer management device in one embodiment;
[0053] Figure 6 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0054] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0055] In one exemplary embodiment, such as Figure 1 As shown, a timer management method is provided. This embodiment illustrates the method by applying it to a computer device. It is understood that this method can also be applied to a server, and to a system including both a computer device and a server, and is implemented through the interaction between the computer device and the server. In this embodiment, the method includes the following steps:
[0056] S201, when the graphical user interface (GUI) is started, generates a global timer management object.
[0057] The Graphical User Interface (GUI) is a user interface design method that allows users to interact with a computer system through graphical elements. In this embodiment, when the GUI is started, preset code can be executed to generate a global timer management object.
[0058] It should be noted that the global timer management object generated in this embodiment can uniformly configure default policies for all timers, while also supporting individual timers to configure their own policies. This enables controllable status of each timer task and component sharing, allowing for unified addition and control of multiple timers.
[0059] S202, upon detecting the start of the target task, invoke the global timer management object to create the target timer corresponding to the target task.
[0060] In this embodiment, if the target task starts in the subsequent business interface, the global timer management object can be invoked to create a target timer corresponding to the target task. The task type of the created timer task can be distinguished, where the task type can include system-level timers and business timers. System-level timers are considered to require user awareness throughout the entire application lifecycle, while business timers only require awareness in a specific business function. As an optional implementation, upon detecting the start of a target task, the type of the target task can be determined first, and then the global timer management object can be invoked to create a target timer based on the target task type.
[0061] S203 manages the target timer based on a preset management strategy.
[0062] In this embodiment, after creating the target timer corresponding to the target task, the target timer can run based on a preset management strategy. As an optional implementation, the preset management strategy may include at least one of the following: Step A, controlling the target timer to execute the timed task according to a preset period; Step B, controlling the timed task based on the operation information of the target task. That is, after creating the target timer corresponding to the target task, and before the timer task is manually removed, the created target timer executes the timed task according to the preset period by default. During the execution of the target timer task, if a change in the target task's operation information is detected, the timed task is controlled based on the target task's operation information. This achieves centralized control, state management, component communication, and reasonable resource reclamation of all timer tasks within the system throughout the complete lifecycle of the GUI application.
[0063] In the above timer management method, a global timer management object is generated when the graphical user interface (GUI) is started. When the target task is detected to be started, the global timer management object is called to create the target timer corresponding to the target task. Based on the preset management strategy, the target timer is managed. Through the generated global timer management object, the system can achieve centralized control, state management, component communication, and reasonable resource reclamation of all timer tasks in the system throughout the entire life cycle of the GUI application, thereby realizing centralized management of timers.
[0064] The following will explain in detail the control method for controlling a timed task based on the operation information of the target task. In an exemplary embodiment, step B above includes:
[0065] If a switching operation targeting the target task is detected during the execution of the target timer's scheduled task, then the scheduled task is paused; or,
[0066] If a removal operation is detected during the execution of the target task by the target timer, then the timed task is destroyed; or,
[0067] If a switch from another task to the target task is detected, the target timer is controlled to continue executing the timed task according to the preset period.
[0068] Typically, during the execution of a timer task, there will be transitions in the timer task's state. Figure 2 This diagram illustrates the flow of a timer task state, as shown below. Figure 2As shown, during the task execution phase, the timer task is divided into three states: sleep, continuing execution, and destroyed. Different user manual operations correspond to different states. When the user does not manually intervene, the timer task always executes according to the set time interval.
[0069] Please continue reading Figure 2 The example diagram illustrates the flow of timer task states. In this embodiment, as an optional implementation, if a switching operation for the target task is detected during the execution of the target timer's timed task, the timed task will be paused, and timing for the target task will stop. If a removal operation for the target task is detected during the execution of the target timer's timed task, the timed task will be destroyed. If a switch from another task to the target task is detected, the target timer will continue to execute the timed task according to the aforementioned preset period.
[0070] In addition, in this embodiment, as an optional implementation method, when destroying the timed task, a global unified interface can be called to destroy the timed task. Destroying the timed task by calling the global unified interface can avoid memory leaks caused by omissions in clearing.
[0071] In this embodiment, based on the different operation information of the target task during the execution of the timer task, different control methods for the timer task are set. Before the timer task is manually removed, the timer task is executed according to the specified periodic strategy by default. During the execution of the timer task, if the user is detected to manually switch to another window, the default strategy is to pause the timer task, change the timer state to a dormant state, and stop occupying resources. When the user switches back to the current window, all timer tasks continue to execute. When accessing different services, by adding timer tasks, manually removing timer tasks, and listening for switching to other windows, the system can achieve centralized control, state management, component communication, and reasonable resource reclamation of all timer tasks within the system throughout the complete lifecycle of the GUI application.
[0072] In some scenarios, the global timer management object also needs to accurately determine the time interval between the last and next scheduled task. In an exemplary embodiment, such as... Figure 3 As shown, the above method also includes:
[0073] S301, determine whether the callback function of the target timer returns a Promise object.
[0074] The Promise object is used to handle asynchronous operations. It represents the final completion (or failure) of an asynchronous operation and its result value. The Promise object has three states: pending, fulfilled, and rejected. Once the state changes, it is irreversible.
[0075] In this embodiment, it can be determined whether the callback function of the target timer returns a Promise object, and dynamic interval control can be achieved by listening to the state of the Promise object.
[0076] As an optional implementation, in this embodiment, it can be determined whether the callback function of the target timer returns a Promise object by judging the type of the return value of the callback function and detecting whether there is a `then` method (where `then` is a function). For example, if it is determined that the type of the callback function's return value is an object and it contains a `then` method, then it is determined that the callback function of the target timer returns a Promise object.
[0077] S302, if so, then after obtaining the execution result of the previous callback function, start calculating the remaining execution time of the next scheduled task.
[0078] S303, if not, then after the last callback function is executed, start calculating the remaining execution time of the next scheduled task.
[0079] In this embodiment, if it is determined that the callback function of the target timer returns a Promise object, the remaining execution time of the next scheduled task is calculated after obtaining the execution result of the previous callback function. If it is determined that the callback function of the target timer does not return a Promise object, the remaining execution time of the next scheduled task is calculated after the execution of the previous callback function.
[0080] In this embodiment, by determining whether the callback function of the target timer returns a Promise object, if the callback function returns a Promise object, the remaining execution time of the next scheduled task is calculated after obtaining the execution result of the previous callback function. If the callback function does not return a Promise object, the remaining execution time of the next scheduled task is calculated after the execution of the previous callback function. This effectively breaks the problem that setInterval() executes at a fixed time interval regardless of the scenario, and to a certain extent ensures that the system runs more stably.
[0081] The timer management method proposed in this application will be explained and illustrated below through a complete embodiment, such as... Figure 4As shown, the timer management method may include:
[0082] When the GUI starts, a global timer management object is generated. In subsequent business interfaces, this object can be called to create target timers for the target tasks. At this point, timer task types are distinguished as system-level timers and business timers. System-level timers are considered to require user awareness throughout the entire application lifecycle, while business timers only require awareness within a specific business function. After adding a timer task, unless it is manually removed, the timer task executes according to the specified periodicity strategy by default. During timer task execution, if the user manually switches to another window, the default strategy is to pause the timer task, changing its state to sleep and ceasing resource consumption. When the user switches back to the current window, all timer tasks resume execution.
[0083] By generating a globally unique timer manager object during initialization, and by adding or removing timer tasks and listening for switching to other windows when accessing different business functions, the system can achieve centralized control, state management, component communication, and reasonable resource reclamation of all timer tasks within the system throughout the entire lifecycle of the GUI application.
[0084] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps. It is understood that the steps in different embodiments can be freely combined as needed, and all non-contradictory solutions formed by such combinations are within the scope of protection of this application.
[0085] Based on the same inventive concept, this application also provides a timer management device for implementing the timer management method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more timer management device embodiments provided below can be found in the limitations of the timer management method described above, and will not be repeated here.
[0086] In one exemplary embodiment, such as Figure 5 As shown, a timer management device is provided, including: a generation module, a creation module, and a management module, wherein:
[0087] The generation module is used to generate a global timer management object when the graphical user interface (GUI) is started.
[0088] The module is created to call the global timer management object and create the target timer corresponding to the target task when the target task is detected to have started.
[0089] The management module is used to manage target timers based on preset management strategies.
[0090] The timer management device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, so it will not be described again here.
[0091] In one embodiment, the above-mentioned management module includes at least one of a first management unit and a second management unit, wherein:
[0092] The first management unit is used to control the target timer to execute timed tasks according to a preset cycle.
[0093] The second management unit is used to control the scheduled tasks based on the operation information of the target task.
[0094] The timer management device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, so it will not be described again here.
[0095] In one embodiment, the second management unit is configured to pause the timed task if a switching operation for the target task is detected during the execution of the timed task by the target timer; or,
[0096] If a removal operation is detected during the execution of the target task by the target timer, then the timed task is destroyed; or,
[0097] If a switch from another task to the target task is detected, the target timer is controlled to continue executing the timed task according to the preset period.
[0098] The timer management device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, so it will not be described again here.
[0099] In one embodiment, the second management unit is used to call a globally unified interface to destroy the scheduled task.
[0100] The timer management device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, so it will not be described again here.
[0101] In one embodiment, the above-mentioned creation module includes: a creation unit, wherein:
[0102] The creation unit is used to call the global timer management object and create a target timer based on the type of the target task when the start of the target task is detected.
[0103] The timer management device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, so it will not be described again here.
[0104] In one embodiment, the above-described apparatus further includes: a determining module, a first calculation module, and a second calculation module, wherein:
[0105] The determination module is used to determine whether the callback function of the target timer returns a Promise object.
[0106] The first calculation module is used to calculate the remaining execution time of the next scheduled task after obtaining the execution result of the previous callback function if the callback function returns a Promise object.
[0107] The second calculation module is used to calculate the remaining execution time of the next scheduled task after the previous callback function is executed if the callback function does not return a Promise object.
[0108] The timer management device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, so it will not be described again here.
[0109] Each module in the aforementioned timer management device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0110] In one exemplary embodiment, a computer device is provided, the internal structure of which can be as shown in the figure. Figure 6As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When the computer program is executed by the processor, it implements a timer management method. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0111] Those skilled in the art will understand that Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0112] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0113] When the graphical user interface (GUI) is started, a global timer management object is generated;
[0114] Upon detecting the start of a target task, the global timer management object is invoked to create the target timer corresponding to the target task;
[0115] The target timer is managed based on a preset management strategy.
[0116] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0117] Control the target timer to execute timed tasks according to a preset period;
[0118] Control the scheduled task based on the operation information of the target task.
[0119] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0120] If a switching operation targeting the target task is detected during the execution of the target timer's scheduled task, then the scheduled task is paused; or,
[0121] If a removal operation is detected during the execution of the target task by the target timer, then the timed task is destroyed; or,
[0122] If a switch from another task to the target task is detected, the target timer is controlled to continue executing the timed task according to the preset period.
[0123] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0124] Call the globally unified interface to destroy the scheduled task.
[0125] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0126] Upon detecting the start of a target task, the global timer management object is invoked to create a target timer based on the type of the target task.
[0127] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0128] Determine whether the callback function of the target timer returns a Promise object;
[0129] If so, after obtaining the execution result of the previous callback function, start calculating the remaining execution time of the next scheduled task;
[0130] If not, the remaining execution time for the next scheduled task will be calculated after the previous callback function is executed.
[0131] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor:
[0132] When the graphical user interface (GUI) is started, a global timer management object is generated;
[0133] Upon detecting the start of a target task, the global timer management object is invoked to create the target timer corresponding to the target task;
[0134] The target timer is managed based on a preset management strategy.
[0135] In one embodiment, when the computer program is executed by a processor, it further performs the following steps:
[0136] Control the target timer to execute timed tasks according to a preset period;
[0137] Control the scheduled task based on the operation information of the target task.
[0138] In one embodiment, when the computer program is executed by a processor, it further performs the following steps:
[0139] If a switching operation targeting the target task is detected during the execution of the target timer's scheduled task, then the scheduled task is paused; or,
[0140] If a removal operation is detected during the execution of the target task by the target timer, then the timed task is destroyed; or,
[0141] If a switch from another task to the target task is detected, the target timer is controlled to continue executing the timed task according to the preset period.
[0142] In one embodiment, when the computer program is executed by a processor, it further performs the following steps:
[0143] Call the globally unified interface to destroy the scheduled task.
[0144] In one embodiment, when the computer program is executed by a processor, it further performs the following steps:
[0145] Upon detecting the start of a target task, the global timer management object is invoked to create a target timer based on the type of the target task.
[0146] In one embodiment, when the computer program is executed by a processor, it further performs the following steps:
[0147] Determine whether the callback function of the target timer returns a Promise object;
[0148] If so, after obtaining the execution result of the previous callback function, start calculating the remaining execution time of the next scheduled task;
[0149] If not, the remaining execution time for the next scheduled task will be calculated after the previous callback function is executed.
[0150] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, performs the following steps:
[0151] When the graphical user interface (GUI) is started, a global timer management object is generated;
[0152] Upon detecting the start of a target task, the global timer management object is invoked to create the target timer corresponding to the target task;
[0153] The target timer is managed based on a preset management strategy.
[0154] In one embodiment, when the computer program is executed by a processor, it further performs the following steps:
[0155] Control the target timer to execute timed tasks according to a preset period;
[0156] Control the scheduled task based on the operation information of the target task.
[0157] In one embodiment, when the computer program is executed by a processor, it further performs the following steps:
[0158] If a switching operation targeting the target task is detected during the execution of the target timer's scheduled task, then the scheduled task is paused; or,
[0159] If a removal operation is detected during the execution of the target task by the target timer, then the timed task is destroyed; or,
[0160] If a switch from another task to the target task is detected, the target timer is controlled to continue executing the timed task according to the preset period.
[0161] In one embodiment, when the computer program is executed by a processor, it further performs the following steps:
[0162] Call the globally unified interface to destroy the scheduled task.
[0163] In one embodiment, when the computer program is executed by a processor, it further performs the following steps:
[0164] Upon detecting the start of a target task, the global timer management object is invoked to create a target timer based on the type of the target task.
[0165] In one embodiment, when the computer program is executed by a processor, it further performs the following steps:
[0166] Determine whether the callback function of the target timer returns a Promise object;
[0167] If so, after obtaining the execution result of the previous callback function, start calculating the remaining execution time of the next scheduled task;
[0168] If not, the remaining execution time for the next scheduled task will be calculated after the previous callback function is executed.
[0169] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0170] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0171] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A timer management method, characterized by, The method comprises: generating a global timer management object in the case of starting a graphical user interface (GUI); calling the global timer management object to create a target timer corresponding to a target task in the case of detecting the starting of the target task; managing the target timer based on a preset management strategy.
2. The method of claim 1, wherein, The management of the target timer based on the preset management strategy comprises at least one of the following: controlling the target timer to execute a timing task according to a preset period; controlling the timing task based on operation information of the target task.
3. The method of claim 2, wherein, The control of the timing task based on the operation information of the target task comprises: suspending the timing task if a switching operation for the target task is detected during the execution of the timing task by the target timer; or destroying the timing task if a removal operation for the target task is detected during the execution of the timing task by the target timer; or controlling the target timer to continue to execute the timing task according to the preset period if it is detected that the target task is switched from another task.
4. The method of claim 3, wherein, The destruction of the timing task comprises: calling a global unified interface to destroy the timing task.
5. The method of claim 1, wherein, The calling of the global timer management object to create the target timer corresponding to the target task in the case of detecting the starting of the target task comprises: calling the global timer management object to create the target timer based on the type of the target task in the case of detecting the starting of the target task.
6. The method according to any one of claims 1 to 5, characterized in that, The method further comprises: determining whether a callback function of the target timer returns a Promise object; if yes, starting to calculate the remaining execution time of the next timing task after obtaining the execution result of the last callback function; and if no, starting to calculate the remaining execution time of the next timing task after the execution of the last callback function.
7. A timer management apparatus characterized by comprising: The device comprises: a generating module configured to generate a global timer management object in the case of starting a graphical user interface (GUI); a creating module configured to call the global timer management object to create a target timer corresponding to a target task in the case of detecting the starting of the target task; a management module configured to manage the target timer based on a preset management strategy.
8. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that, The processor executes the computer program to implement the steps of the method of any one of claims 1 to 6.
9. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 6.
10. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 6.