Coroutine-based timing method and device, storage medium and product

By determining the start node in the coroutine timing task and executing the timing task, the problem of timing errors in the coroutine timing task is solved, and the timing accuracy is improved.

CN119440763APending Publication Date: 2025-02-14GUANGZHOU BAOLUN ELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411512135.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-28
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

When executing timing tasks through coroutines, timing errors are prone to occur, affecting timing accuracy.

Method used

By determining that the node acquisition conditions are currently met, the start node of the timing task is determined based on the acquired timing information and the current time node, and the timing task is performed based on the start node.

Benefits of technology

Effectively avoid timing tasks being executed in the wrong time, improve timing accuracy, and ensure the normal execution of the timing function of the coroutine.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119440763A_ABST
    Figure CN119440763A_ABST
Patent Text Reader

Abstract

The invention provides a coroutine-based timing method and device, a storage medium and a product, and relates to the technical field of computers. The coroutine-based timing method comprises the following steps: determining that a node acquisition condition is currently satisfied, and determining a starting node corresponding to a timing task according to acquired timing information and a current time node, the node acquisition condition comprising any one of timing task starting and timing task recovery, and the timing information comprising at least one of timing duration and timing scale; and executing the timing task according to the starting node. According to the embodiment of the invention, when the timing task is started or recovered, the starting node of the timing task can be re-determined according to the timing information and the current time node, so that the timing task is effectively prevented from being executed at wrong time, the timing accuracy is improved, and normal execution of the timing function of the coroutine is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and more specifically, to a timing method, device, storage medium and product based on coroutines. Background Art

[0002] As a lightweight thread, coroutines have excellent suspension and resumption functions, and can be bound to the page life cycle, and can automatically cancel the timing when the page disappears. In terms of child thread timing, coroutines can easily switch to the main thread for UI display, so they are particularly suitable for implementing the timing function of a single task.

[0003] The coroutine executes the timed task by timing. When executing the timed task, it is executed based on the start time set for the timed task. However, when executing the timed task, it is easy for the task to be paused or the start time of the task to be inconsistent with the set start time, which causes the timed task to be executed at the wrong time, resulting in timing errors and affecting the accuracy of timing. Summary of the invention

[0004] The embodiments of the present application provide a timing method, device, storage medium and product based on coroutines, which can solve the problem that timing errors are prone to occur when executing timing tasks through coroutines, affecting the timing accuracy. In order to achieve this purpose, the embodiments of the present application provide the following solutions.

[0005] According to one aspect of an embodiment of the present application, a coroutine-based timing method is provided, including:

[0006] Determine whether the node acquisition condition is currently satisfied, and determine the start node corresponding to the timing task according to the acquired timing information and the current time node, wherein the node acquisition condition includes any one of starting the timing task and resuming the timing task, and the timing information includes at least one of the timing duration and the timing scale;

[0007] A timing task is executed according to the start node.

[0008] In a possible implementation, the timing information includes a timing duration, and determining a start node corresponding to the timing task according to the acquired timing information and the current time node includes:

[0009] Get the current time node and the remaining time corresponding to the timing task;

[0010] The start node is determined according to the current time node, the remaining time and the timing time.

[0011] In a possible implementation, executing the timing task according to the start node includes:

[0012] Obtaining the remaining time of the timing task according to the current time node, the timing duration, and the start node;

[0013] If it is determined that the coroutine is in an active state and the remaining time is greater than zero, the timing loop corresponding to the timing task is executed.

[0014] In a possible implementation, the timing information further includes a timing scale, and the execution of the timing cycle corresponding to the timing task includes:

[0015] Obtain the current time, and update the remaining time according to the current time, the timing information, and the start node;

[0016] If it is determined that the remaining time is less than or equal to zero, the timing task is terminated.

[0017] In a possible implementation, updating the remaining time according to the current time, the timing information, and the start node includes:

[0018] Get the execution cost corresponding to the last timing cycle;

[0019] The target timing scale corresponding to the current timing cycle is adjusted based on the execution consumption, and the remaining time is updated according to the target timing scale, the current time, the timing duration, and the start node.

[0020] In a possible implementation, obtaining the execution consumption corresponding to the previous timing cycle includes:

[0021] Obtaining the number of cycles corresponding to the timing cycle, determining the expected time node corresponding to the previous timing cycle according to the number of cycles and the timing scale, and determining the execution consumption based on the expected time node and the actual time node corresponding to the previous timing cycle;

[0022] Alternatively, the execution consumption is determined according to the granularity of the timing scale and an actual time node corresponding to a previous timing cycle.

[0023] In a possible implementation, updating the remaining time according to the current time, the timing information, and the start node includes:

[0024] Obtain historical execution consumption and coroutine resource information corresponding to historical timing cycles, and determine a consumption factor according to the historical execution consumption, the coroutine resource information, and the timing scale;

[0025] Predicting the execution consumption corresponding to the next timing cycle according to the consumption factor and the execution consumption of the current timing cycle;

[0026] The timing scale corresponding to the next timing cycle is adjusted based on the prediction result, and the remaining time is updated in the next timing cycle according to the timing scale corresponding to the next timing cycle.

[0027] According to one aspect of an embodiment of the present application, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the method described above.

[0028] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method described above are implemented.

[0029] According to one aspect of an embodiment of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps of the method described above are implemented.

[0030] The beneficial effects of the technical solution provided by the embodiment of the present application are:

[0031] The coroutine-based timing method provided in the present application determines the start node corresponding to the timing task according to the acquired timing information and the current time node when determining that the node acquisition condition is currently met, the node acquisition condition includes any one of starting the timing task and resuming the timing task, and the timing information includes at least one of the timing duration and the timing scale; the timing task is executed according to the start node, and the embodiment of the present application can redetermine the start node of the timing task according to the timing information and the current time node when the timing task is started or resumed, thereby effectively avoiding the timing task from being executed at the wrong time, improving the accuracy of timing, and ensuring the normal execution of the timing function of the coroutine. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following is a brief introduction to the drawings required for use in describing the embodiments of the present application.

[0033] Figure 1 A flowchart of a coroutine-based timing method provided in an embodiment of the present application;

[0034] Figure 2 An execution flow chart of a coroutine-based timing method provided in an embodiment of the present application;

[0035] Figure 3 A structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0036] The embodiments of the present application are described below in conjunction with the drawings in the present application. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions of the embodiments of the present application.

[0037] It will be understood by those skilled in the art that, unless specifically stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application refer to that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude the implementation of other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the present technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the one element may be directly connected or coupled to the other element, or it may refer to that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein indicates at least one of the items defined by the term, for example, "A and / or B" indicates that it is implemented as "A", or is implemented as "A", or is implemented as "A and B".

[0038] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.

[0039] The following describes several exemplary embodiments to illustrate the technical solutions of the embodiments of the present application and the technical effects produced by the technical solutions of the present application. It should be noted that the following embodiments can refer to, draw on or combine with each other, and the same terms, similar features and similar implementation steps in different embodiments will not be described repeatedly.

[0040] The coroutine-based timing method, device, storage medium and product provided in this application are intended to solve at least one technical problem existing in the prior art.

[0041] A coroutine-based timing method is provided in an embodiment of the present application. The coroutine-based timing method can be used for mobile phones, computers, smart watches, and other terminals that can use coroutines for timing.

[0042] Alternatively, if Figure 1 , Figure 2 As shown, the timing method based on coroutine is executed to realize the timing task through the coroutine, and the method includes:

[0043] S101: Determine whether a node acquisition condition is currently satisfied, and determine a start node corresponding to a timing task according to the acquired timing information and the current time node.

[0044] Optionally, the node acquisition condition includes any one of starting a timing task and resuming a timing task, and determining whether the node acquisition condition is currently met includes: receiving an operation instruction corresponding to the timing task, and detecting whether the node acquisition condition is currently met according to the operation instruction; if it is determined that the operation instruction is to start a timing task or resume a timing task, then determining that the node acquisition condition is currently met and executing the operation instruction.

[0045] Optionally, before detecting whether the node acquisition condition is currently met according to the operation instruction, the timing information corresponding to the setting instruction can also be obtained in response to the setting instruction, and the timing information includes at least one of the timing duration and the timing scale. The timing task can be set according to the setting instruction, and the timing information can be obtained when setting the timing task.

[0046] Specifically, the timing duration can be input by any object in the timer system related to the timing task, the developer, the user of the terminal, or the server connected to the terminal. The timing duration determines the total duration of the task. The timing scale is the time interval between each check of the remaining time or execution of the timing task during the execution of the coroutine (such as the time interval between two timing cycles). The timing scale determines the interval between each check and update of the remaining time.

[0047] In one embodiment, the timing duration and the timing scale are parameters set before the timing starts. The timing duration can be 10 seconds, 30 minutes, or other values, and the timing scale can be 1000ms or other time intervals. When the timing scale is 1000ms, during the execution of the timing task, starting from the start node, the remaining time is checked every 1000ms, and the recorded remaining time is updated according to the detection result.

[0048] Optionally, the timing information includes the timing duration, and determining the start node corresponding to the timing task based on the acquired timing information and the current time node includes: acquiring the current time node and the remaining duration corresponding to the timing task; determining the start node based on the current time node, the remaining duration and the timing duration.

[0049] Optionally, the remaining time is the time that the timing task needs to be executed. When the timing task is started, the remaining time is equal to the timing time. When the timing task is resumed, the remaining time = the timing time - the time that the timing task has been executed. When executing the timing task, the terminal can store the remaining time of the timing task so as to quickly obtain the remaining time when calculating the start node.

[0050] Optionally, determining the start node according to the current time node, the remaining duration and the timing duration includes: subtracting the timing duration from the current time node, adding the remaining duration to the result, and the node corresponding to the generated time value is the start node. Among them, current node - timing duration + remaining duration = current node - (timing duration - remaining duration) = current node - (elapsed duration of the timing task), and the start node is determined as the start node corresponding to the timing task. Using a new start node facilitates accurate timing to avoid the start time of the timing task being inconsistent with the set time node or the interference caused by pausing the timing task.

[0051] In one embodiment, it is determined that the current task is to resume the timing task, the current time and timing information corresponding to the current time node are obtained, and the start time corresponding to the start node is calculated based on the obtained information. The relevant calculation formula can be: timing duration - elapsed time = timing duration - (current time - start time) = start time + timing duration - current time. The start time corresponding to the start node is used to continue timing from the correct time point when the timing task is resumed. Among them, the initially set timing duration is equal to the remaining duration, and the remaining duration decreases according to the time period, so the start time corresponding to the start node is always less than or equal to the current time corresponding to the current node), the start node of the timing task is determined based on the calculated start time, and then the timing cycle is started based on the start node.

[0052] S102: Execute the timing task according to the start node.

[0053] Optionally, executing the timing task according to the start node includes: obtaining the remaining time of the timing task according to the current time node, the timing duration and the start node; if it is determined that the coroutine is in an active state and the remaining time is greater than zero, executing the timing loop corresponding to the timing task.

[0054] In one embodiment, during the execution of a timing task, the remaining time corresponding to the timing task is obtained and it is determined whether the coroutine used for timing related to the timing task is in an active state. If it is determined that the coroutine is in an inactive state (such as the coroutine is closed or does not execute the timing task) or the remaining time is less than or equal to 0, the timing task is stopped; if it is detected that the corresponding coroutine is in an active state or the remaining time is greater than 0, the timing loop related to the timing task is executed.

[0055] Optionally, the timing information also includes a timing scale, and executing a timing loop corresponding to the timing task includes: obtaining the current time, updating the remaining time according to the current time, the timing information and the start node; if it is determined that the remaining time is less than or equal to zero, ending the timing task.

[0056] Specifically, when executing a timing task, it is detected whether the current time is the time to update the remaining time according to the calculated starting node and the timing scale. If so, the time required for the current timing task to be executed is calculated according to the current time, the timing duration in the timing information, the timing scale and the calculated starting node, and the remaining time is determined as the remaining time. If it is determined that the remaining time is less than or equal to 0, it is determined that the timing task is completed and the timing task is stopped.

[0057] Optionally, the time period between two timing marks can be determined as a timing cycle, and each timing task can include multiple timing cycles. When there are multiple timing tasks or multiple timing cycles of a timing task, due to the overhead of coroutine execution and method call, the actual consumption time of each timing cycle is greater than the set time. Therefore, when executing the timing cycle, it is necessary to calibrate the timing mark according to the consumed time, and update the remaining time based on the calibration result. Among them, updating the remaining time according to the current time, timing information and start node includes: obtaining the execution consumption corresponding to the previous timing cycle; adjusting the target timing mark corresponding to the current timing cycle based on the execution consumption, and updating the remaining time according to the target timing mark, current time, timing duration and start node.

[0058] In one embodiment, the actual time consumed by the previous timing cycle is calculated, and then the waiting time of the next cycle is reduced by the corresponding consumption. For example, if the set timing scale is 1, but due to system overhead, the previous timing cycle actually consumed 1.2 seconds, then the waiting time of the next timing cycle (i.e., the timing scale corresponding to the next timing cycle) can be 0.8 seconds to compensate for the 0.2 second delay.

[0059] Optionally, obtaining the execution consumption corresponding to the last timing cycle includes: obtaining the number of cycles corresponding to the timing cycle, determining the expected time node corresponding to the last timing cycle according to the number of cycles and the timing scale, and determining the execution consumption based on the expected time node and the actual time node corresponding to the last timing cycle; or determining the execution consumption according to the granularity of the timing scale and the actual time node corresponding to the last timing cycle (the actual time corresponding to the actual time node can be rounded based on the timing scale, and the excess time after rounding is determined as the execution consumption). The time scale of the coroutine suspension (i.e., the time waiting for the next timing cycle) is set to the timing scale minus the lost execution consumption, so that the actual end time of the next timing cycle can be as consistent as possible with the corresponding expected time node.

[0060] In one embodiment, the timing scale is determined as the cycle waiting time of each timing cycle, and the expected end time of each timing cycle is determined according to the cycle waiting time and the start node. When executing the timing cycle, the actual end time of the current time cycle is obtained, and the actual end time is compared with the expected end time to obtain the difference between the two. The timing scale corresponding to the next timing cycle is subtracted from the difference to obtain an updated timing scale, and the remaining time is updated in the next timing cycle according to the timing scale. Specifically, a counter can be added in each cycle, and the expected time node corresponding to each timing cycle is obtained by multiplying the counter by the timing scale, so the lost execution consumption is equal to the actual time node at the end of each timing cycle minus the expected time node. The second is that for the timing scale with large particles (the particle size is greater than the preset particle size), a rounding operation can be performed, and the excess value is the lost execution consumption. For example, if the timing scale is 1 second, 3.3 seconds have passed when the current timing cycle ends, then the lost execution consumption is 0.3 seconds.

[0061] Optionally, an execution cost is calculated for each timing loop, which is the difference between the actual elapsed time and the expected time, usually calculated by checking the difference between the current time and the scheduled time after the coroutine is suspended. For example, if a timing loop is scheduled to execute at 3 seconds, but it actually executes in 3.1 seconds, then the lost execution cost is 0.1 seconds.

[0062] Optionally, when calculating the execution consumption, the execution consumption lost in the next timing cycle can also be calculated forward, wherein the remaining time is updated according to the current time, timing information and start node, including: obtaining the historical execution consumption and coroutine resource information corresponding to the historical timing cycle, and determining the consumption factor according to the historical execution consumption, coroutine resource information and timing scale; predicting the execution consumption corresponding to the next timing cycle according to the consumption factor and the execution consumption of the current timing cycle; adjusting the timing scale corresponding to the next timing cycle based on the prediction result, and updating the remaining time in the next timing cycle according to the timing scale corresponding to the next timing cycle.

[0063] Optionally, the coroutine resource information includes CPU usage, coroutine scheduling overhead, CPU load, and other parameters that can affect execution consumption. The historical execution consumption may include execution consumption corresponding to multiple historical timing cycles.

[0064] Optionally, when the consumption factor is 0, the timing scale may not be adjusted, and the remaining time may be directly updated according to the timing scale in the timing information.

[0065] In one embodiment, the historical execution consumption includes the execution consumption of each timing cycle in the first five timing cycles. The execution consumption of each timing cycle in the historical execution consumption is added, and the sum is divided by 5 to obtain the average value of the execution consumption. The average value is adjusted according to the coroutine resource information, and the adjusted average value is determined as the consumption factor. Among them, the consumption factor can be equal to the adjustment parameter corresponding to the average value / coroutine resource information. After obtaining the consumption factor, the execution consumption generated by the current timing cycle is multiplied by the consumption factor, and the multiplication result is used as the execution consumption of the next timing cycle. According to the execution consumption of the current timing cycle and the execution consumption of the next timing cycle, the timing scale corresponding to the next timing cycle is adjusted (such as the timing scale minus the execution consumption of the current timing cycle and the execution consumption of the next timing cycle). The next timing cycle is executed based on the adjusted timing scale.

[0066] Optionally, after calibrating the timing scale for the next timing cycle, the timing scale is suspended and the next timing cycle is executed based on the timing scale.

[0067] The coroutine-based timing method provided in the embodiment of the present application determines the start node corresponding to the timing task according to the acquired timing information and the current time node when determining that the node acquisition condition is currently met, the node acquisition condition includes any one of starting the timing task and resuming the timing task, and the timing information includes at least one of the timing duration and the timing scale; the timing task is executed according to the start node, and the embodiment of the present application can redetermine the start node of the timing task according to the timing information and the current time node when the timing task is started or resumed, thereby effectively avoiding the timing task from being executed at the wrong time, improving the accuracy of timing, and ensuring the normal execution of the timing function of the coroutine.

[0068] In an optional embodiment, an electronic device is provided, such as Figure 3 As shown, Figure 3 The electronic device 4000 shown includes: a processor 4001 and a memory 4003. The processor 4001 and the memory 4003 are connected, such as through a bus 4002. Optionally, the electronic device 4000 may also include a transceiver 4004, which may be used for data interaction between the electronic device and other electronic devices, such as data transmission and / or data reception. It should be noted that in actual applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present application.

[0069] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.

[0070] The bus 4002 may include a path to transmit information between the above components. The bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 4002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0071] Memory 4003 can be ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or it can be EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disc, optical disk, digital versatile disc, Blu-ray disc, etc.), magnetic disk storage medium, other magnetic storage devices or any other medium that can be used to carry or store computer programs and can be read by a computer, without limitation here.

[0072] The memory 4003 is used to store the computer program for executing the embodiment of the present application, and the execution is controlled by the processor 4001. The processor 4001 is used to execute the computer program stored in the memory 4003 to implement the steps shown in the above method embodiment.

[0073] Among them, the electronic device can be any electronic product that can interact with an object, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an interactive network television (IPTV), a smart wearable device, etc.

[0074] The electronic device may also include a network device and / or an object device, wherein the network device includes, but is not limited to, a single network server, a server group consisting of multiple network servers, or a cloud consisting of a large number of hosts or network servers for cloud computing.

[0075] The network where the electronic device is located includes but is not limited to the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (Virtual Private Network, VPN), etc.

[0076] An embodiment of the present application provides a computer-readable storage medium, which includes a computer program. When the computer program is executed by a processor, the steps and corresponding contents of the aforementioned method embodiment can be implemented.

[0077] An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps and corresponding contents of the aforementioned method embodiment can be implemented.

[0078] The terms "first", "second", "third", "fourth", "1", "2", etc. (if any) in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than that shown or described in the drawings.

[0079] It should be understood that, although each operation step is indicated by arrows in the flowchart of the embodiment of the present application, the implementation order of these steps is not limited to the order indicated by the arrows. Unless clearly stated herein, in some implementation scenarios of the embodiment of the present application, the implementation steps in each flowchart can be performed in other orders according to demand. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on actual implementation scenarios. Some or all of these sub-steps or stages may be executed at the same time, and each sub-step or stage in these sub-steps or stages may also be executed at different times respectively. In different scenarios of execution time, the execution order of these sub-steps or stages may be flexibly configured according to demand, and the embodiment of the present application does not limit this.

[0080] The above is only an optional implementation method for some implementation scenarios of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the technical concept of the solution of the present application, other similar implementation methods based on the technical ideas of the present application are also within the protection scope of the embodiments of the present application.

Claims

1. A timing method based on coroutine, characterized in that: include: Determine whether the node acquisition condition is currently satisfied, and determine the start node corresponding to the timing task according to the acquired timing information and the current time node, wherein the node acquisition condition includes any one of starting the timing task and resuming the timing task, and the timing information includes at least one of the timing duration and the timing scale; A timing task is executed according to the start node.

2. The timing method based on coroutine according to claim 1, characterized in that: The timing information includes the timing duration, and determining the start node corresponding to the timing task according to the acquired timing information and the current time node includes: Get the current time node and the remaining time corresponding to the timing task; The start node is determined according to the current time node, the remaining time and the timing time.

3. The timing method based on coroutine according to claim 2, characterized in that: The executing the timing task according to the start node includes: Obtaining the remaining time of the timing task according to the current time node, the timing duration, and the start node; If it is determined that the coroutine is in an active state and the remaining time is greater than zero, the timing loop corresponding to the timing task is executed.

4. The timing method based on coroutine according to claim 3, characterized in that: The timing information also includes a timing scale, and the timing cycle corresponding to the execution of the timing task includes: Obtain the current time, and update the remaining time according to the current time, the timing information, and the start node; If it is determined that the remaining time is less than or equal to zero, the timing task is terminated.

5. The timing method based on coroutine according to claim 4, characterized in that: The updating of the remaining time according to the current time, the timing information and the start node includes: Get the execution cost corresponding to the last timing cycle; The target timing scale corresponding to the current timing cycle is adjusted based on the execution consumption, and the remaining time is updated according to the target timing scale, the current time, the timing duration, and the start node.

6. The timing method based on coroutine according to claim 5, characterized in that: The obtaining of the execution consumption corresponding to the previous timing cycle includes: Obtaining the number of cycles corresponding to the timing cycle, determining the expected time node corresponding to the previous timing cycle according to the number of cycles and the timing scale, and determining the execution consumption based on the expected time node and the actual time node corresponding to the previous timing cycle; Alternatively, the execution consumption is determined according to the granularity of the timing scale and an actual time node corresponding to a previous timing cycle.

7. The timing method based on coroutine according to claim 4, characterized in that: The updating of the remaining time according to the current time, the timing information and the start node includes: Obtain historical execution consumption and coroutine resource information corresponding to historical timing cycles, and determine a consumption factor according to the historical execution consumption, the coroutine resource information, and the timing scale; Predicting the execution consumption corresponding to the next timing cycle according to the consumption factor and the execution consumption of the current timing cycle; The timing scale corresponding to the next timing cycle is adjusted based on the prediction result, and the remaining time is updated in the next timing cycle according to the timing scale corresponding to the next timing cycle.

8. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 7.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.