Task processing method, device, storage medium and electronic equipment
By creating an application-level target execution coroutine to handle unfinished tasks when the root coroutine is destroyed, the problem of uncontrollable sub-coroutines caused by root coroutine cancellation is solved, and the task processing efficiency and stability are improved.
Patent Information
- Application Number
- CN202210446275.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-26
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2042-04-26
AI Technical Summary
When the root coroutine is canceled, the uncontrollable and time-consuming operations of the child coroutines cause the root coroutine to suspend, causing uncontrollable logical problems that are difficult to effectively handle with existing technologies.
When the root coroutine destruction instruction is monitored, it is determined whether the child coroutine task can be cancelled. If not, a target execution coroutine is created and the unfinished tasks are scheduled to be processed in the coroutine. The life cycle of the target execution coroutine is at the application level.
By registering and canceling the monitoring in the child coroutine and creating a target execution coroutine, the task processing efficiency is improved and the stability of the task status and the continuity of processing are ensured.
Smart Images

Figure CN114995970B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of electronic equipment, and in particular to a task processing method, device, storage medium and electronic equipment. Background Art
[0002] With the rapid development of processing power and storage capacity of electronic devices, a large number of applications have been rapidly spread and used, improving the quality of life of users and the sense of entertainment during use.
[0003] The basic execution unit of an application in a memory environment is a process. A process can have multiple threads, and a thread can have multiple coroutines. In related technologies, coroutines can be divided into root coroutines (i.e., parent coroutines) and child coroutines according to their priorities. For the root coroutine, since there is no higher-level coroutine at the time of creation, the internal context object (Coroutine Context) is an empty context object (Empty Coroutine), so it has an independent feature and is not affected by other coroutines. For child coroutines, since they are generated in the root coroutine scope, their context object is the context object of the root coroutine. In order to maintain stability at runtime, the context object cannot be changed after it is set.
[0004] When the root coroutine is canceled due to external reasons, the child coroutine will be canceled directly, and the internal tasks running in the child coroutine will also be canceled. In some implementations, a method is provided to wait for the coroutine to complete execution, which can be used to wait for the child coroutine to complete its task before canceling the root coroutine. However, if the root coroutine is intercepted by the child coroutine when it needs to be canceled, if the child coroutine is an uncontrollable and time-consuming operation, the root coroutine will remain in a suspended state. The root coroutine may have other business operations, which may lead to uncontrollable logic. Summary of the Invention
[0005] The embodiments of the present application provide a task processing method, device, storage medium, and electronic device, which can improve task processing efficiency.
[0006] In a first aspect, an embodiment of the present application provides a task processing method, including:
[0007] When a destruction instruction of the target root coroutine is monitored, determining whether the currently unfinished task of the sub-coroutine can be canceled, wherein the target root coroutine and the sub-coroutine are in a parent-child relationship;
[0008] If not, create a target execution coroutine, wherein the life cycle of the target execution coroutine is at the application level;
[0009] Schedule the unfinished tasks to the target execution coroutine for processing.
[0010] In a second aspect, an embodiment of the present application provides a task processing device, including:
[0011] A first determining unit is configured to determine whether a currently unfinished task of a sub-coroutine can be canceled when a destruction instruction of a target root coroutine is monitored, wherein the target root coroutine and the sub-coroutine are in a parent-child relationship;
[0012] a creating unit, configured to create a target execution coroutine when the determining unit determines that the target execution coroutine has a lifecycle at the application level;
[0013] The first processing unit is used to schedule unfinished tasks to the target execution coroutine for processing.
[0014] In one embodiment, the device further comprises:
[0015] An acquisition unit, configured to acquire a coroutine identifier of the sub-coroutine before creating a target execution coroutine;
[0016] A second determining unit is configured to determine whether a target historical coroutine identifier matching the coroutine identifier exists in a target mapping relationship set, wherein the target mapping relationship set includes a correspondence between historical coroutine identifiers and historical tasks;
[0017] A second processing unit is configured to, when the second determining unit determines that the result is yes, obtain a corresponding historical execution coroutine based on the target historical coroutine identifier, and schedule the unfinished task to the historical execution coroutine for processing;
[0018] The creating unit is configured to create a target execution coroutine when the second determining unit determines that the result is no.
[0019] In one embodiment, the device further comprises:
[0020] An updating unit is used to update the target mapping relationship set based on the coroutine identifier and the unexecuted tasks after creating the target execution coroutine.
[0021] In some embodiments, the first processing unit is configured to:
[0022] Create a channel queue;
[0023] Add the unfinished task to the channel queue;
[0024] The target execution coroutine obtains the unfinished task from the channel queue for processing.
[0025] In one embodiment, the device further comprises:
[0026] a third determining unit, configured to determine an importance level of a new task when detecting that a new task needs to be added to the channel queue;
[0027] A sorting unit, configured to update the sorting of tasks in the channel queue based on the importance level of the new task
[0028] In one embodiment, the device further comprises:
[0029] A destruction unit is used to dispatch the unfinished task to the target execution coroutine for processing, and then respond to the destruction instruction to destroy the target root coroutine and the sub-coroutine.
[0030] In a third aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein a plurality of instructions are stored in the storage medium, and the instructions are suitable for being loaded by a processor to execute the above-mentioned task processing method.
[0031] In a fourth aspect, an embodiment of the present application further provides an electronic device, including a processor and a memory, wherein the processor is electrically connected to the memory, the memory is used to store instructions and data, and the processor is used to execute the above-mentioned task processing method.
[0032] This application implements a method that registers a cancellation listener in a child coroutine. When it receives a destroy instruction from the target root coroutine, it determines whether the child coroutine's currently unfinished task is cancelable. If the task is not cancelable, a target execution coroutine is created and the unfinished task is executed in the target execution coroutine through scheduling, thereby improving the task status and task processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0034] Figure 1 This is a flowchart of a task processing method provided in an embodiment of the present application.
[0035] Figure 2 This is another flowchart of the task processing method provided in an embodiment of the present application.
[0036] Figure 3 It is a structural diagram of a task processing device provided in an embodiment of the present application.
[0037] Figure 4 It is a structural diagram of an electronic device provided in an embodiment of the present application.
[0038] Figure 5 This is another structural diagram of the electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0039] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without making creative efforts are within the scope of protection of this application.
[0040] The embodiments of the present application provide a task processing method, apparatus, storage medium, and electronic device, which will be described in detail below.
[0041] In one embodiment, a task processing method is provided, which is applied to electronic devices such as smart phones, tablet computers, and laptop computers. Figure 1 , the specific process of the task processing method can be as follows:
[0042] 101. When a destroy instruction of the target root coroutine is monitored, determine whether the unfinished task of the child coroutine can be canceled, where the target root coroutine and the child coroutine are in a parent-child relationship.
[0043] A coroutine is a more lightweight entity than a thread. Just as a process can have multiple threads, a thread can have multiple coroutines. A coroutine is neither a process nor a thread, but a special function that can be suspended at a certain place and can be resumed from the suspension point. Coroutines are not managed by the operating system kernel, but are completely controlled by the program, that is, they are executed in user mode. The switching content of the coroutine is the hardware context, and the switching memory is stored in the user's own variables (user stack or heap). The switching process of the coroutine is only in user mode (that is, it does not fall into kernel mode), and does not consume resources like thread switching. Therefore, the switching efficiency is high and the performance is greatly improved.
[0044] The embodiment of this application will elaborate on this solution based on Kotlin coroutine. For the Android system, there are many ways to create a Kotlin coroutine. For example, a coroutine scope can be created through the GlobalScope.launch() or CoroutineScope(Context).launch() method, and the corresponding coroutine body can be executed in the coroutine scope to achieve the creation of the coroutine. The coroutine scope is used to provide the operating environment of the coroutine and specify the scope of the coroutine, and the coroutine body is the program segment that operates within the coroutine.
[0045] If the root coroutine is canceled first, the child coroutine will normally be canceled as well. In practice, you can set a listener via an interface callback, register a cancellation or other listener in the child coroutine, and call back when the root coroutine is canceled to monitor the running status of the root coroutine.
[0046] In this embodiment, tasks may be marked by setting identifiers to distinguish between regular tasks (ie, tasks that can be canceled) and special tasks (ie, tasks that cannot be canceled).
[0047] 102. If the request cannot be canceled, a target execution coroutine is created, wherein the lifecycle of the target execution coroutine is at the application level.
[0048] The target execution coroutine is a special root coroutine, which is used to execute the processing unit and provide a coroutine environment for the processing unit to execute.
[0049] Specifically, if the unfinished task cannot be cancelled, a global root coroutine is created as the target execution coroutine to subsequently execute the above special task. It should be noted that the life cycle of the target execution coroutine in the embodiment of the present application is at the application level, that is, the target execution coroutine will never be destroyed during the operation of the application.
[0050] 103. Schedule the unfinished tasks to the target execution coroutine for processing.
[0051] In one embodiment, when scheduling unfinished tasks to a target execution coroutine for processing, the following process may be included:
[0052] Create a channel queue;
[0053] Add unfinished tasks to the channel queue;
[0054] The target execution coroutine obtains unfinished tasks from the channel queue for processing.
[0055] Specifically, when there are unfinished tasks in the Channel queue, the Channel.sent method is called to send the task to the target coroutine. The target coroutine then calls the Channel.receive method to receive the pending task and execute it directly. Because Channel is concurrency-safe, no additional concurrency control is required, so data can be retrieved and executed sequentially.
[0056] When there are no pending tasks in the channel queue, it can be suspended based on the Channel suspension mechanism, and can be unsuspended the next time there is a pending task.
[0057] In one embodiment, when it is detected that a new task needs to be added to the channel queue, the importance level of the new task can be determined, and then the order of tasks in the channel queue can be updated based on the importance level of the new task, and the order of tasks with higher importance levels can be adjusted forward, and the order of tasks with lower importance levels can be adjusted backward, so that tasks with higher importance levels can be processed first to ensure their completion.
[0058] In one embodiment, after dispatching the unfinished task to the target execution coroutine for processing, the system may respond to the destruction instruction and execute an operation to destroy the target root coroutine and its child coroutines.
[0059] In actual applications, since there may be multiple subtasks running in a coroutine, tasks running under the same coroutine correspond to the same coroutine identifier and can therefore run in the same execution coroutine. Based on this, in this embodiment, in order to reduce redundancy and save terminal resources, the execution coroutine can be reused, that is, tasks corresponding to the same coroutine identifier can share an execution coroutine. That is, in one embodiment, before creating the target execution coroutine, the following operations may also be included:
[0060] Get the coroutine identifier of the sub-coroutine;
[0061] Determine whether a target historical coroutine identifier matching the coroutine identifier exists in a target mapping relationship set, where the target mapping relationship set includes: a correspondence between historical coroutine identifiers and historical tasks;
[0062] If yes, determine the corresponding historical execution coroutine based on the target historical coroutine identifier, and dispatch the unfinished task to the historical execution coroutine for processing;
[0063] If not, execute the operation of creating the target execution coroutine.
[0064] In practical applications, this target mapping relationship set can be represented as a map set of key-value pairs. For example, the key in the map set represents the historical coroutine identifier (i.e., the coroutine identifier), and the value represents the historical task (i.e., the task that the coroutine needs to run). The coroutine stores the historical coroutine identifier and historical task in a map set. When the root coroutine lifecycle changes, the key is determined, the corresponding value is retrieved, and the corresponding execution coroutine is dispatched (if it has not yet been created) for processing.
[0065] In one embodiment, after creating the target execution coroutine, the target mapping relationship set can also be updated based on the coroutine identifier and the unexecuted task, so that subsequent tasks under the associated coroutine can reuse the target execution coroutine.
[0066] As can be seen from the above, the task processing method provided by this embodiment registers a cancellation listener in the child coroutine. When it listens to the destroy instruction of the target root coroutine, it determines whether the child coroutine's currently unfinished task is cancelable. If the task is not cancelable, a target execution coroutine is created and the unfinished task is executed in the target execution coroutine through scheduling means, thereby achieving task status promotion and improving task processing efficiency.
[0067] In another embodiment, a method for supporting task state promotion within a sub-coroutine scope is also provided. Below, the solution in this application will be described in detail using the Kotlin coroutine system as an example.
[0068] refer to Figure 2 In this embodiment, a listener can be set in the child coroutine, which will be called back when the root coroutine is cancelled. At this time, if the task being executed by the child coroutine is a special task that needs to be continued, a dispatch unit can be sent to the dispatcher. The sub-coroutine identifier of the dispatch unit can be Job.key (that is, the identifier of the current sub-coroutine, any identifier that satisfies the global uniqueness).
[0069] Among them, the distribution unit is the smallest unit of distribution. In this embodiment, the distribution unit is composed of the current sub-coroutine identifier and the Runnable object (that is, the task that needs to be continued). The distributor is essentially a map collection, the key is the sub-coroutine identifier, and the value is a Channel object. Channel is a concurrent and safe queue used for communication between coroutines. Since the queue has a certain capacity, when the capacity is exceeded and additional tasks are added, the buffer task will be executed. In this solution, the buffer task is conflated, that is, a merge strategy. For example, when the sender sends task A, task B, and task C, and the consumer has not consumed them yet, the buffer only retains the latest task, that is, task C.
[0070] Continue to refer Figure 2 The dispatcher dispatches. If the dispatch unit's sub-coroutine identifier doesn't exist in the dispatcher's key set, a new Channel queue is created with the value. Therefore, the dispatcher adds a map with the sub-coroutine identifier as the key and the Channel element as the value, and simultaneously creates an execution coroutine. If the dispatch unit's sub-coroutine identifier exists in the dispatcher's key set, the dispatcher proceeds directly to the next step, reusing the previously created execution unit to execute the processing unit.
[0071] The dispatcher iterates over all values in the key and extracts data from them. If there are unexecuted processing units in the value (i.e., the Channel queue), the task is sent to the executing coroutine via the Channel.sent method. If there are no processing units to be executed in the value, the task is suspended (Channel has a suspension mechanism that will unsuspend the task the next time a processing unit is available).
[0072] It's important to note that in this embodiment, the coroutine lifecycle is application-level and is not canceled during application execution. The coroutine receives a processing unit via the Channel.receive method and directly executes the processing unit's tasks. Because Channel is concurrency-safe, no additional concurrency control is required; sequential data fetching and execution are sufficient.
[0073] As can be seen from the above, the task processing method provided in this embodiment, without disrupting the internal operating structure of the coroutine, registers and cancels monitoring in the child coroutine, sends a distribution unit after meeting custom conditions, implements the distribution strategy internally through producer-consumer queues, consumes the coroutine, and executes the execution rights of special tasks that meet the conditions in the root coroutine through scheduling, thereby improving the task status. In addition, by centralizing task processing within the executing coroutine, it facilitates the decoupling of the task architecture and is compatible with the current execution of Kotlin coroutines.
[0074] In another embodiment of the present application, a task processing device is also provided. The task processing device can be integrated into an electronic device in the form of software or hardware, and the electronic device can specifically include a mobile phone, a tablet computer, a laptop computer, etc. Figure 3 As shown, the task processing device 300 may include: a first determining unit 301, a creating unit 302 and a first processing unit 303, wherein:
[0075] A first determining unit 301 is configured to determine whether an unfinished task of a sub-coroutine can be canceled when a destroy instruction of a target root coroutine is monitored, wherein the target root coroutine and the sub-coroutine are in a parent-child relationship;
[0076] A creating unit 302 is configured to create a target execution coroutine when the determining unit determines that the target execution coroutine has an application-level lifecycle;
[0077] The first processing unit 303 is used to schedule unfinished tasks to the target execution coroutine for processing.
[0078] In one embodiment, the task processing device 300 further includes:
[0079] An acquisition unit, configured to acquire a coroutine identifier of the sub-coroutine before creating a target execution coroutine;
[0080] A second determining unit is configured to determine whether a target historical coroutine identifier matching the coroutine identifier exists in a target mapping relationship set, wherein the target mapping relationship set includes a correspondence between historical coroutine identifiers and historical tasks;
[0081] A second processing unit is configured to, when the second determining unit determines that the result is yes, obtain a corresponding historical execution coroutine based on the target historical coroutine identifier, and schedule the unfinished task to the historical execution coroutine for processing;
[0082] The creating unit 302 is configured to create a target execution coroutine when the second determining unit determines that the result is no.
[0083] In one embodiment, the task processing device 300 further includes:
[0084] An updating unit is used to update the target mapping relationship set based on the coroutine identifier and the unexecuted tasks after creating the target execution coroutine.
[0085] In some implementations, the first processing unit 303 is specifically configured to:
[0086] Create a channel queue;
[0087] Add the unfinished task to the channel queue;
[0088] The target execution coroutine obtains the unfinished task from the channel queue for processing.
[0089] In one embodiment, the task processing device 300 further includes:
[0090] a third determining unit, configured to determine an importance level of a new task when detecting that a new task needs to be added to the channel queue;
[0091] A sorting unit, configured to update the sorting of tasks in the channel queue based on the importance level of the new task
[0092] In one embodiment, the task processing device 300 further includes:
[0093] A destruction unit is used to dispatch the unfinished task to the target execution coroutine for processing, and then respond to the destruction instruction to destroy the target root coroutine and the sub-coroutine.
[0094] As can be seen from the above, the task processing device provided by the embodiment of the present application, by registering a cancellation monitor in the child coroutine, determines whether the currently unfinished task of the child coroutine can be canceled when the destruction instruction of the target root coroutine is monitored. If the task is not cancelable, a target execution coroutine is created, and the unfinished task is executed in the target execution coroutine through scheduling means, thereby achieving task status improvement and improving task processing efficiency.
[0095] In another embodiment of the present application, an electronic device is provided, which can be a smart terminal such as a smart phone or a tablet computer. Figure 4 As shown, the electronic device 400 includes a processor 401 and a memory 402. The processor 401 is electrically connected to the memory 402.
[0096] The processor 401 is the control center of the electronic device 400. It uses various interfaces and lines to connect various parts of the entire electronic device. By running or loading applications stored in the memory 402 and calling data stored in the memory 402, it executes various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole.
[0097] In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to one or more application processes into the memory 402 according to the following steps, and the processor 401 runs the applications stored in the memory 402 to implement various functions:
[0098] When a target root coroutine's destruction instruction is monitored, determine whether the unfinished task of the sub-coroutine can be canceled, where the target root coroutine and the sub-coroutine are in a parent-child relationship;
[0099] If not, create a target execution coroutine, where the lifecycle of the target execution coroutine is at the application level;
[0100] Schedule unfinished tasks to the target execution coroutine for processing.
[0101] In one embodiment, before creating the target execution coroutine, the processor 401 may perform the following operations:
[0102] Get the coroutine identifier of the sub-coroutine;
[0103] Determine whether a target historical coroutine identifier matching the coroutine identifier exists in a target mapping relationship set, where the target mapping relationship set includes: a correspondence between historical coroutine identifiers and historical tasks;
[0104] If yes, determine the corresponding historical execution coroutine based on the target historical coroutine identifier, and schedule the unfinished task to the historical execution coroutine for processing;
[0105] If not, execute the step of creating the target execution coroutine.
[0106] In one embodiment, after creating the target execution coroutine, the processor 401 may perform the following operations:
[0107] Based on the coroutine identifier and the unfinished task, the target mapping relationship set is updated.
[0108] In one embodiment, when scheduling the unfinished task to the target execution coroutine for processing, the processor 401 may further perform the following operations:
[0109] Create a channel queue;
[0110] Add the unfinished task to the channel queue;
[0111] The target execution coroutine obtains the unfinished task from the channel queue for processing.
[0112] In one embodiment, when detecting that a new task needs to be added to the channel queue, the processor 401 may perform the following operations:
[0113] By determining the importance level of the new task;
[0114] Update the order of tasks in the channel queue based on the importance level of the new task.
[0115] In one embodiment, after dispatching the unfinished task to the target execution coroutine for processing, the processor 401 may further perform the following operations:
[0116] In response to the destroy instruction, the target root coroutine and the child coroutine are destroyed.
[0117] Memory 402 can be used to store applications and data. The applications stored in memory 402 contain instructions that can be executed by the processor. Applications can be composed of various functional modules. Processor 401 executes various functional applications and tasks by running the applications stored in memory 402.
[0118] In some embodiments, as Figure 5 As shown, the electronic device 400 further includes: a display screen 403, a control circuit 404, a radio frequency circuit 405, an input unit 406, a sensor 408, and a power supply 409. The processor 401 is electrically connected to the display screen 403, the control circuit 404, the radio frequency circuit 405, the input unit 406, the camera 407, the sensor 408, and the power supply 409.
[0119] The display screen 403 may be used to display information input by a user or information provided to a user, as well as various graphical user interfaces of the electronic device. These graphical user interfaces may be composed of images, texts, icons, videos, and any combination thereof.
[0120] The control circuit 404 is electrically connected to the display screen 403 and is used to control the display screen 403 to display information.
[0121] The radio frequency circuit 405 is used to transmit and receive radio frequency signals, so as to establish wireless communication with electronic devices or other electronic devices through wireless communication, and to transmit and receive signals with servers or other electronic devices.
[0122] The input unit 406 may be configured to receive input numbers, characters, or user characteristics (e.g., fingerprints), and generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control. The input unit 406 may include a fingerprint recognition module.
[0123] The camera 407 can be used to collect image information. The camera can be a single camera with one lens, or can have two or more lenses.
[0124] The sensor 408 is used to collect external environment information. The sensor 408 may include an ambient brightness sensor, an acceleration sensor, a light sensor, a motion sensor, and other sensors.
[0125] The power supply 409 is used to supply power to various components of the electronic device 400. In some embodiments, the power supply 409 can be logically connected to the processor 401 through a power management system, so that the power management system can manage charging, discharging, and power consumption.
[0126] although Figure 5 Not shown in the figure, the electronic device 400 may further include a speaker, a Bluetooth module, etc., which will not be described in detail here.
[0127] As can be seen from the above, the electronic device provided by the embodiment of the present application, by registering and canceling monitoring in the sub-coroutine, determines whether the sub-coroutine's currently unfinished task can be canceled when it monitors the destruction instruction of the target root coroutine. If the task cannot be canceled, a target execution coroutine is created, and the unfinished task is executed in the target execution coroutine through scheduling means, thereby achieving task status improvement and improving task processing efficiency.
[0128] In some embodiments, a computer-readable storage medium is further provided, in which a plurality of instructions are stored. The instructions are suitable for being loaded by a processor to execute any of the above-mentioned task processing methods.
[0129] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, which may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.
[0130] The above is a detailed introduction to the task processing method, device, storage medium and electronic device provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A task processing method, characterized in that: include: When a destruction instruction of the target root coroutine is monitored, determining whether the currently unfinished task of the sub-coroutine can be canceled, wherein the target root coroutine and the sub-coroutine are in a parent-child relationship; If not, create a target execution coroutine, wherein the life cycle of the target execution coroutine is at the application level; Dispatching unfinished tasks to the target execution coroutine for processing; Before creating the target execution coroutine, it also includes: Get the coroutine identifier of the sub-coroutine; Determine whether a target historical coroutine identifier matching the coroutine identifier exists in a target mapping relationship set, wherein the target mapping relationship set includes: a correspondence between historical coroutine identifiers and historical tasks; If yes, determine the corresponding historical execution coroutine based on the target historical coroutine identifier, and schedule the unfinished task to the historical execution coroutine for processing; If not, execute the step of creating the target execution coroutine.
2. The task processing method according to claim 1, characterized in that: After creating the target execution coroutine, it also includes: Based on the coroutine identifier and the unexecuted tasks, the target mapping relationship set is updated.
3. The task processing method according to claim 1, characterized in that: Scheduling the unfinished task to the target execution coroutine for processing includes: Create a channel queue; Add the unfinished task to the channel queue; The target execution coroutine obtains the unfinished task from the channel queue for processing.
4. The task processing method according to claim 3, characterized in that: Also includes: When a new task is detected to be added to the channel queue, the importance level of the new task is determined; The order of tasks in the channel queue is updated based on the importance level of the new task.
5. The task processing method according to claim 1, characterized in that: After dispatching the unfinished task to the target execution coroutine for processing, the method further includes: In response to the destroy instruction, the target root coroutine and the child coroutine are destroyed.
6. A task processing device, characterized in that: include: A first determining unit is configured to determine whether a currently unfinished task of a sub-coroutine can be canceled when a destruction instruction of a target root coroutine is monitored, wherein the target root coroutine and the sub-coroutine are in a parent-child relationship; a creating unit, configured to create a target execution coroutine when the determining unit determines that the target execution coroutine has a lifecycle at the application level; A first processing unit is used to dispatch unfinished tasks to the target execution coroutine for processing; An acquisition unit, configured to acquire a coroutine identifier of the sub-coroutine before creating a target execution coroutine; A second determining unit is configured to determine whether a target historical coroutine identifier matching the coroutine identifier exists in a target mapping relationship set, wherein the target mapping relationship set includes a correspondence between historical coroutine identifiers and historical tasks; A second processing unit is configured to, when the second determining unit determines that the result is yes, obtain a corresponding historical execution coroutine based on the target historical coroutine identifier, and schedule the unfinished task to the historical execution coroutine for processing; The creating unit is configured to create a target execution coroutine when the second determining unit determines that the result is no.
7. A computer-readable storage medium, characterized in that The storage medium stores a plurality of instructions, which are suitable for being loaded by a processor to execute the task processing method according to any one of claims 1 to 5.
8. An electronic device, characterized in that: It includes a processor and a memory, the processor is electrically connected to the memory, and the memory is used to store instructions and data; the processor is used to execute the task processing method described in any one of claims 1 to 5.