An asynchronous invocation method, apparatus, computer device, and readable storage medium
By creating child loop threads within the task loop thread to execute asynchronous tasks in parallel, the problem of tasks waiting for the result of the previous task in existing asynchronous call methods is solved, thus improving task execution efficiency and stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2021-04-15
- Publication Date
- 2026-05-26
Smart Images

Figure CN115220879B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, specifically to an asynchronous invocation method, apparatus, computer device, and readable storage medium. Background Technology
[0002] Operating systems have become incredibly sophisticated, and threads are one of their masterpieces. In a single-threaded environment, a computer is a strictly von Neumann machine, meaning that a task can only begin execution after the previous task has finished.
[0003] With multithreading support, tasks can be processed asynchronously. That is, asynchronous calls allow the next task to proceed without waiting for the previous task to finish. However, existing asynchronous call methods have several limitations. For example, in scenarios where the current task must wait for the thread to return the result of the previous task, existing asynchronous call methods are not suitable, which will reduce task execution efficiency. Summary of the Invention
[0004] This application provides an asynchronous invocation method, apparatus, and electronic device that improves the execution efficiency of tasks in applications.
[0005] This application provides an asynchronous invocation method, including:
[0006] Determine a set of tasks to be executed for the application, the set of tasks to be executed including at least one task to be executed in the order of execution;
[0007] The task loop thread of the application is used to execute the tasks in the task set to be executed.
[0008] When it is detected that the current task being executed by the task loop thread meets the preset triggering condition, the asynchronous call waiting function of the task loop thread is called to create a sub-loop thread for executing at least one target task. The target task includes the task set to be executed, which is executed after the current task.
[0009] At least one target task is executed using the sub-loop thread;
[0010] When the asynchronous call waiting function is detected to have received the execution result of the current task, the task loop thread is triggered to execute the unexecuted tasks in the set of tasks to be executed based on the execution result.
[0011] Accordingly, embodiments of this application also provide an asynchronous invocation device, including:
[0012] A determining unit is configured to determine a set of tasks to be executed by an application, the set of tasks to be executed including at least one task to be executed in an execution order;
[0013] The first execution unit is used to execute the tasks in the task set to be executed using the task loop thread of the application.
[0014] The calling unit is used to call the asynchronous call waiting function of the task loop thread when it is detected that the current task being executed by the task loop thread meets the preset triggering condition, so as to create a sub-loop thread for executing at least one target task. The target task includes the tasks in the task set to be executed that are executed after the current task.
[0015] The second execution unit is used to execute at least one target task using the sub-loop thread;
[0016] The triggering unit is used to trigger the task loop thread to execute the unexecuted tasks in the set of tasks to be executed based on the execution result when the asynchronous call waiting function receives the execution result of the current task.
[0017] In one embodiment, the calling unit includes:
[0018] The determining subunit is used to determine the task type of the current task when it is detected that the current task being executed by the task loop thread meets a preset triggering condition;
[0019] Add a sub-unit to add a location identifier to the set of tasks to be executed, based on the task type of the current task;
[0020] The calling sub-unit is used to call the asynchronous call waiting function of the task loop thread according to the location identifier, and to filter the at least one target task from the set of tasks to be executed according to the location identifier, so as to create a sub-loop thread for executing at least one target task using the asynchronous call waiting function.
[0021] In one embodiment, the added subunit includes:
[0022] The acquisition module is used to obtain target task filtering information from a preset relationship mapping table based on the task type of the current task;
[0023] An add module is used to add location identifiers to the set of tasks to be executed based on the target task filtering information.
[0024] In one embodiment, the calling subunit includes:
[0025] The triggering module is used to trigger the task execution engine to call the thread creation function to create the sub-loop thread using the asynchronous call waiting function.
[0026] In one embodiment, the triggering unit includes:
[0027] The detection subunit is used to detect the execution status of the target task in the sub-loop thread when the asynchronous call waiting function receives the execution result of the current task, and to obtain the execution status of the target task.
[0028] The triggering subunit is used to trigger the task loop thread to execute the unexecuted tasks in the task set to be executed based on the execution status.
[0029] In one embodiment, the trigger subunit includes:
[0030] The determination module is used to determine the execution order of the unexecuted tasks in the set of tasks to be executed when it is detected that the sub-loop thread includes unexecuted tasks;
[0031] The triggering module is used to trigger the task loop thread to execute the unexecuted tasks according to the execution order.
[0032] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in the various alternative embodiments described above.
[0033] Accordingly, this application embodiment also provides a storage medium storing instructions, which, when executed by a processor, implement any of the asynchronous calling methods provided in this application embodiment.
[0034] This application embodiment can determine a set of tasks to be executed in an application, which includes at least one task to be executed in an order of execution. The application's task loop thread is used to execute the tasks in the set. When it is detected that the current task being executed by the task loop thread meets a preset trigger condition, an asynchronous call waiting function of the task loop thread is called to create a sub-loop thread for executing at least one target task. The sub-loop thread is used to execute at least one target task. When it is detected that the asynchronous call waiting function receives the execution result of the current task, the task loop thread is triggered to execute unexecuted tasks in the set based on the execution result, thereby improving task execution efficiency. Attached Figure Description
[0035] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0036] Figure 1 This is a schematic diagram of a scenario for the asynchronous invocation method provided in an embodiment of this application;
[0037] Figure 2 This is a flowchart illustrating the asynchronous invocation method provided in an embodiment of this application;
[0038] Figure 3 This is a schematic diagram of the task to be executed for the asynchronous invocation method provided in this application embodiment;
[0039] Figure 4 This is another scenario diagram illustrating the asynchronous invocation method provided in the embodiments of this application;
[0040] Figure 5 This is a task diagram illustrating the asynchronous invocation method provided in an embodiment of this application;
[0041] Figure 6 This is another scenario diagram illustrating the asynchronous invocation method provided in the embodiments of this application;
[0042] Figure 7 This is another scenario diagram illustrating the asynchronous invocation method provided in the embodiments of this application;
[0043] Figure 8 This is another scenario diagram illustrating the asynchronous invocation method provided in the embodiments of this application;
[0044] Figure 9 This is another scenario diagram illustrating the asynchronous invocation method provided in the embodiments of this application;
[0045] Figure 10 This is another scenario diagram illustrating the asynchronous invocation method provided in the embodiments of this application;
[0046] Figure 11 This is another flowchart illustrating the asynchronous invocation method provided in the embodiments of this application;
[0047] Figure 12 This is a schematic diagram of another task to be executed for the asynchronous invocation method provided in this application embodiment;
[0048] Figure 13 This is a schematic diagram of another task to be executed for the asynchronous invocation method provided in this application embodiment;
[0049] Figure 14This is a schematic diagram of another task to be executed for the asynchronous invocation method provided in this application embodiment;
[0050] Figure 15 This is a schematic diagram of the structure of the testing device provided in the embodiments of this application;
[0051] Figure 16 This is another structural schematic diagram of the testing device provided in the embodiments of this application;
[0052] Figure 17 This is a schematic diagram of the terminal structure provided in the embodiments of this application. Detailed Implementation
[0053] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. However, the described embodiments are only some embodiments of this application, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0054] This application proposes an asynchronous invocation method, which can be executed by an asynchronous invocation device integrated into a computer device. The computer device can include at least one of a terminal and a server. That is, the asynchronous invocation device can be integrated into a terminal, a server, or a terminal and server capable of mutual communication. The terminal can be a smartphone, tablet, laptop, personal computer (PC), smart home device, wearable electronic device, VR / AR device, in-vehicle computer, etc. The server can be an interconnection server for multiple heterogeneous systems or a backend server, a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, and big data and artificial intelligence platforms, etc.
[0055] In one embodiment, such as Figure 1The asynchronous invocation device can be integrated into computer devices such as terminals or servers to implement the asynchronous invocation method proposed in the embodiments of this application. Specifically, the computer device can determine a set of tasks to be executed by an application, which includes at least one task to be executed arranged in a predetermined order; execute the tasks to be executed in the set of tasks using the application's task loop thread; when it is detected that the current task being executed by the task loop thread meets a preset trigger condition, invoke the asynchronous call wait function of the task loop thread to create a sub-loop thread for executing at least one target task, wherein the target task is a task in the task set whose execution order is after the current task; execute at least one target task using the sub-loop thread; when it is detected that the asynchronous call wait function receives the execution result of the current task, trigger the task loop thread to execute the unexecuted tasks in the set of tasks to be executed based on the execution result.
[0056] In this embodiment, asynchronous operation includes suspending the current task when it becomes blocked, allowing other unexecuted tasks to be performed. There are various reasons why the current task might become blocked, such as a long execution time or an exception occurring during execution.
[0057] The following will provide a detailed description of each example. It should be noted that the order of description of the following embodiments is not intended to limit the preferred order of the embodiments.
[0058] This application will describe the embodiments from the perspective of an asynchronous calling device, which can be integrated into a computer device, such as a server or a terminal.
[0059] like Figure 2 The above provides an asynchronous invocation method, the specific process of which includes:
[0060] 101. Determine the set of tasks to be executed for the application, which includes at least one task to be executed in a predetermined order.
[0061] Applications include computer programs that perform one or more specific functions. They run in interactive mode, can interact with the users of the application, and have a visual display interface.
[0062] For example, applications can include software on various terminals. These include mobile phone applications (APPs), tablet applications, laptop applications, personal computer (PC) applications, and so on.
[0063] For example, applications can include browsers, video playback software, game software, and so on.
[0064] For example, applications can also include mini-programs. A mini-program is an application that can be used without downloading or installing it. To provide users with more diverse business services, developers can create corresponding mini-programs for terminal applications (such as instant messaging applications, shopping applications, email applications, etc.). These mini-programs can be embedded as sub-applications within the terminal application, and by running the sub-application (i.e., the corresponding mini-program) within the application, corresponding business services can be provided to the user.
[0065] In one embodiment, a computer program includes a set of instructions that instruct a computer device or other device with information processing capabilities to perform actions or make judgments. It is typically written in a programming language and runs on a computer device.
[0066] Different applications can be written in different programming languages. For example, mini-programs can be written in JavaScript. Mobile software can be written in Java or C++, and so on.
[0067] In one embodiment, since applications generally have rich functionality, an application may include hundreds or thousands of computer programs, each of which can be regarded as a task in the application.
[0068] For example, the application is a small program that can play videos. This small program includes multiple computer programs, one of which plays the video and another of which stops playing the video. The computer program that plays the video can be considered as one task, and the computer program that stops playing the video can be considered as another task.
[0069] For example, such as Figure 3 The image shows an example of a computer program. In this example, doFoo1, doFoo2, and doFoo3 can all be considered computer programs, and therefore can all be considered tasks. Here, param1 is the input parameter of doFoo1, and result1 is the execution result of doFoo1. Similarly, result1 is the input parameter of doFoo2, result2 is the execution result of doFoo2, result2 is the input parameter of doFoo3, and result3 is the execution result of doFoo3.
[0070] The tasks to be executed include unexecuted tasks within the application. The set of tasks to be executed includes at least one task arranged in execution order. The execution order may include the order in which the tasks to be executed are performed within the task set. Unexecuted tasks include tasks within the application that have not yet been executed.
[0071] In one embodiment, an application may generate multiple unexecuted tasks within the same time period, but the application's task loop thread cannot immediately complete all of these unexecuted tasks. To execute the multiple unexecuted tasks in an orderly and targeted manner, several tasks to be executed can be identified from the multiple unexecuted tasks and added to a task set to be executed, so that the task loop thread can first complete the tasks to be executed in the task set to be executed.
[0072] Once the task loop thread has completed executing all tasks in the task set, it can identify several more unexecuted tasks from the application's remaining tasks and add them to the task set, allowing the task loop thread to execute them. This process is repeated continuously, ensuring that the task loop thread executes unexecuted tasks in the application in an orderly manner.
[0073] For example, if an application has 20 unexecuted tasks in the current time period, it can identify 10 tasks to be executed from these 20 unexecuted tasks and add these 10 tasks to the task set to be executed, so that these 10 tasks can be executed by the task loop thread.
[0074] In one embodiment, when several tasks to be executed are determined from a plurality of unexecuted tasks, the tasks to be executed can be determined from the plurality of unexecuted tasks based on at least one of the following: task type, generation time, timeliness, etc.
[0075] For example, when multiple tasks are not yet executed, tasks with higher time sensitivity can be designated as pending tasks. Similarly, tasks with longer generation times can be designated as pending tasks, and so on.
[0076] In one embodiment, the execution order can be determined by the time when the tasks to be executed enter the set of tasks to be executed. For example, if task 1 enters the set of tasks to be executed before task 2, then task 1 can be executed before task 2.
[0077] In one embodiment, the execution order can be determined by the order in which the tasks to be executed are written in the application. For example, when the application is written using JavaScript, if task 1 is written before task 2, then task 1 can be executed before task 2 in the set of tasks to be executed.
[0078] In one embodiment, multiple tasks in an application can be categorized based on their nature. For example, tasks in an application can be divided into scheduler tasks, microtasks, asynchronous thread tasks, and other tasks.
[0079] Scheduler tasks include tasks with timed characteristics.
[0080] For example, in applications written in JavaScript, scheduler tasks can include `setTimeout()`, `setInterval()`, `requestAnimationFrame()`, and so on. `setTimeout()` is used to call a function or evaluate an expression after a specified number of milliseconds. `setInterval()` is used to call a function or evaluate an expression at specified intervals (in milliseconds). `requestAnimationFrame()` can provide a browser or app with an interface for timed loop operations, enabling a unified refresh mechanism for various webpage animation effects within the browser or app, thereby saving system resources, improving system performance, and enhancing visual effects.
[0081] Microtasks include tasks that need to be executed by an internal queue in the task loop thread.
[0082] For example, in applications written in the JavaScript programming language, microtasks can include Promise(), and so on. Promise() represents a future event and is used to deliver messages for asynchronous operations.
[0083] Asynchronous thread tasks include tasks that need to be executed by sub-loop threads.
[0084] For example, in applications written in the JavaScript programming language, asynchronous thread tasks can include request(), websocket(), and so on. request() can request and retrieve data. websocket() provides a protocol for full-duplex communication over a single Transmission Control Protocol (TCP) connection, making data exchange between clients and servers simpler and allowing the server to proactively push data to clients.
[0085] Other tasks include those other than scheduler tasks, microtasks, and asynchronous thread tasks.
[0086] In one embodiment, the execution order of the above tasks in the application can be as follows: Figure 4As shown, the scheduler task is executed first, then the microtask, then the asynchronous thread task, and finally the other tasks.
[0087] In one embodiment, since the application includes a computer program, and the computer program is usually written in a certain programming language, applications written in different programming languages will have different execution flows when performing the task to be performed.
[0088] For example, when the computer program in an application is written in the Java programming language, because Java is a multithreaded programming language, the tasks to be executed in the application are performed by multiple task loop threads.
[0089] For example, when the computer program in an application is written in the JavaScript programming language, because JavaScript is a single-threaded programming language, there is only one task loop thread to execute the tasks to be performed in the application.
[0090] The set of tasks to be executed can be determined based on the number of task loop threads.
[0091] For example, when an application has multiple task loop threads, the set of tasks to be executed by the application can be determined for each of the multiple task loop threads.
[0092] For example, when there are 100 unprocessed tasks in an application and 3 task loop threads, the corresponding task sets to be executed can be determined for each of the 3 task loop threads based on the generation time and / or timeliness of the unprocessed tasks, and each task set to be executed includes several tasks to be executed.
[0093] For example, if there are 100 unprocessed tasks in an application and only one task loop thread, then a set of tasks to be executed can be determined for that task loop thread.
[0094] 102. Utilize the application's task loop thread to execute tasks in the task pool.
[0095] In this context, a task loop thread is the smallest unit of computation that the operating system in a computer device can schedule; that is, a task loop thread is the unit in a computer device capable of executing tasks generated by an application. For example, if a computer device is likened to a factory, a task loop thread is like an assembly line within that factory, continuously and cyclically executing various tasks generated by the application.
[0096] In one embodiment, since the application includes a computer program, and the computer program is usually written in a certain programming language, applications written in different programming languages will have different execution flows when performing the task to be performed.
[0097] For example, when the computer program in an application is written in the Java programming language, because Java is a multithreaded programming language, the tasks to be executed in the application are performed by multiple task looping threads. This is analogous to a computer factory having multiple production lines; the tasks in the application can be executed by these multiple production lines simultaneously, allowing the computer factory to perform multiple tasks concurrently.
[0098] For example, when the computer program in an application is written in the JavaScript programming language, because JavaScript is a single-threaded programming language, only one task loop thread executes the tasks to be performed in the application. In this case, it's equivalent to a factory with only one assembly line, where all tasks are executed by this assembly line. Furthermore, this assembly line can only complete one task at a time; it cannot complete multiple tasks simultaneously.
[0099] In one embodiment, when only one task loop thread is executing the tasks to be executed in the application, the task loop thread can be used to execute the tasks to be executed in the set of tasks to be executed.
[0100] In one embodiment, when multiple task loop threads execute tasks in an application, the previous step determines the set of tasks to be executed based on the number of task loop threads. For example, when there are 3 task loop threads, a corresponding set of tasks to be executed is determined for each task loop thread. Therefore, the task loop threads can execute the tasks in their respective sets of tasks in parallel.
[0101] In one embodiment, since the tasks to be executed in the task set are arranged in execution order, when the task loop thread of the application is used to execute the tasks to be executed in the task set, the task loop thread will execute the tasks to be executed according to the execution order in the task set.
[0102] For example, if there are three tasks in a task set, with task 1 being the first task, task 2 the second, and task 3 the third, then when the task loop thread executes the tasks, task 1 will be executed first, followed by task 2, and finally task 3.
[0103] In one embodiment, when the tasks to be executed in the task set of the application include scheduler tasks, microtasks, asynchronous thread tasks and other tasks, the task loop thread can be used to execute the tasks in the order of execution.
[0104] In one embodiment, during the execution of tasks in the task set using the application's task loop thread, the tasks in the task set can be continuously monitored, so that when a currently executing task in the task set is detected to meet a preset trigger condition, the currently executing task is processed.
[0105] Because JavaScript is single-threaded, all tasks must be queued; the next task will only execute after the previous one is completed. If a previous task takes a long time, the next task will have to wait, resulting in low execution efficiency.
[0106] 103. When it is detected that the current task being executed by the task loop thread meets the preset triggering conditions, the asynchronous call waiting function of the task loop thread is called to create a sub-loop thread for executing at least one target task. The target tasks include tasks in the task set to be executed that are executed after the current task.
[0107] The current task includes the task currently being executed by the task loop thread.
[0108] The target task includes tasks that are scheduled to be executed after the current task.
[0109] In one embodiment, since the task loop thread executes the tasks to be executed according to the execution order of the task set, the target task may include unexecuted tasks in the task set.
[0110] For example, when an application is written in JavaScript, because JavaScript is single-threaded, tasks in the application can only be executed in a predetermined order. In this case, since the target task includes tasks in the task set that are executed after the current task, the target task can also include unexecuted tasks in the task set.
[0111] Among them, the sub-loop thread includes the thread that executes the task in the task set that follows the current task when the current task executed by the task loop thread meets the preset triggering condition.
[0112] In one embodiment, both the sub-loop thread and the task loop thread have the same function and can process the tasks to be executed in the task set.
[0113] Among them, the asynchronous call waiting function includes functions that can create a sub-loop thread and add tasks in the task set that are executed after the current task to the sub-loop thread for execution.
[0114] In one embodiment, to address the limitations of existing asynchronous invocation methods—for example, in scenarios where the current task must wait for the thread to return the result of the previous task before it can execute, existing asynchronous invocation methods are unsuitable and reduce program efficiency—this application proposes a new asynchronous invocation mechanism. This asynchronous invocation mechanism can be represented by `Signal`.
[0115] The asynchronous call waiting function can be one of the functional functions implementing the asynchronous call mechanism. In one embodiment, the asynchronous call waiting function can be represented in various forms. For example, the asynchronous call waiting function can be represented by signal.wait(). Another example is that the asynchronous call waiting function can be represented by signal.call(), and so on. This application does not limit this aspect.
[0116] The asynchronous call mechanism proposed in this application can be implemented at any location in any task within an application, making it applicable to various application scenarios. This solves the problem that synchronous tasks in applications need to wait for asynchronous calls, thereby improving task execution efficiency.
[0117] The preset trigger conditions include pre-defined conditions that will trigger the asynchronous call to the waiting function. For example, preset trigger conditions may include the task execution time exceeding a preset threshold or the current task waiting for the previous task exceeding a preset threshold, and so on.
[0118] For example, if the execution time of the current task in the task loop thread exceeds 1 millisecond, the asynchronous call wait function of the loop thread can be triggered. As another example, if the execution of the current task in the task loop thread requires waiting for data to return from the previous task, and the waiting time exceeds a preset threshold, the asynchronous call wait function of the task loop thread can be invoked.
[0119] It should be noted that there are no restrictions on the preset trigger conditions here. You can set preset trigger conditions according to various scenarios encountered during task execution in the application that may cause task blocking and reduce task efficiency.
[0120] In one embodiment, when calling an asynchronous wait function, the asynchronous wait function can be inserted after the current task. For example, as... Figure 5 As shown, when the current task doFoo1 meets the preset triggering conditions, an asynchronous wait function signal.wait() can be inserted after doFoo1.
[0121] When an asynchronous wait function is inserted after the current task, all tasks pending execution after the asynchronous wait function can be executed by the child loop thread. For example, ... Figure 5 As shown, both tasks doFoo2 and doFoo3 can be executed using sub-loop threads.
[0122] In one embodiment, when calling the asynchronous call waiting function, the location where the asynchronous call waiting function is called in the task set to be executed can be determined first, and then the asynchronous call waiting function can be called at that location, so that the sub-loop thread created by the asynchronous call waiting function can execute the target task at that location.
[0123] For example, such as Figure 6 As shown, the set of tasks to be executed includes several tasks. When it is detected that the currently executing task in the task loop thread meets a preset trigger condition and calls the asynchronous wait function, the location where the asynchronous wait function is called in the set of tasks to be executed can be determined. For example, it can be... Figure 6 The asynchronous wait function is called at the position of task 6 to be executed, so that the child loop thread created by the asynchronous wait function can execute tasks 1 to 6 to be executed.
[0124] In one embodiment, when it is detected that the current task being executed by the task loop thread meets a preset trigger condition, the task type of the current task can be determined so that the asynchronous call wait function of the task loop thread is invoked according to the task type. Specifically, the step "when it is detected that the current task being executed by the task loop thread meets a preset trigger condition, invoking the asynchronous call wait function of the task loop thread to create a sub-loop thread for executing at least one target task" may include:
[0125] When the task loop thread detects that the current task being executed meets the preset triggering conditions, the task type of the current task is determined.
[0126] Add a location marker to the set of tasks to be executed based on the task type of the current task;
[0127] The asynchronous call wait function of the task loop thread is invoked based on the location identifier, and at least one target task is selected from the set of tasks to be executed based on the location identifier, so as to create a sub-loop thread for executing at least one target task using the asynchronous call function.
[0128] The location identifier includes flags used when invoking the asynchronous call wait function and when selecting the target task from the set of tasks to be executed. In other words, this location identifier indicates how to select the target task from the set of tasks to be executed and how to invoke the asynchronous wait function.
[0129] In one embodiment, the location identifier can take many forms. For example, the location identifier can be a string, etc.
[0130] In one embodiment, multiple tasks in an application can be categorized based on their nature. For example, tasks in the application can be divided into scheduler tasks, microtasks, and asynchronous thread tasks. Therefore, when it is detected that the current task being executed by the task loop thread meets a preset triggering condition, the type of the current task can be determined.
[0131] In one embodiment, since all tasks in the application have task names, and these task names can generally serve as the identifier of the task, that is, the task can be identified by the task name. Therefore, the task type of the current task can be determined by identifying the task name or task content of the current task.
[0132] For example, when the current task is setTimeout(), the task type can be determined to be a scheduler task by recognizing the task name "setTimeout".
[0133] For example, when the current task is Promise(), the task type can be determined to be a microtask by recognizing the task name "Promise".
[0134] In one embodiment, since the time required for the task loop thread to execute different types of tasks and the execution results of different types of tasks may vary, different handling methods are used when calling the asynchronous call waiting function for different types of tasks. Therefore, location markers can be added at different positions in the set of tasks to be executed, based on the different task types of the current task.
[0135] For example, when the task type includes scheduler tasks, microtasks, asynchronous thread tasks, and other tasks, the execution time of asynchronous thread tasks is longer than that of microtasks, and the execution time of microtasks is longer than that of scheduler tasks. Therefore, as... Figure 6 As shown, depending on the task type of the current task, when adding a location marker to the set of tasks to be executed, the asynchronous thread task can add a location marker at task 7, the micro task can add a location marker at task 5, and the scheduler task can add a location marker at task 2. This allows the asynchronous call waiting function to be invoked based on the location marker, and at least one target task to be selected from the set of tasks to be executed.
[0136] In one embodiment, since location markers can be added at different positions in the set of tasks to be executed based on the different task types of the current task, and the positions where location markers are added are related to how the target task is determined, a mapping table relating task types and target tasks can be pre-set, allowing location markers to be added based on this mapping table.
[0137] Specifically, the step "Add location markers to the set of tasks to be executed according to the task type of the current task" includes:
[0138] Based on the task type of the current task, retrieve the target task filtering information from the preset relationship mapping table;
[0139] Add location markers to the set of tasks to be executed based on the target task filtering information.
[0140] The target task filtering information includes the filtering information for the target tasks. For example, the target task filtering information may include at least one of the following: the number of target tasks, the type of target tasks, etc.
[0141] For example, if the current task type is a scheduler task, the target task filter information could be the number of target tasks, which could be 5. Or, if the current task type is a microtask, the target task filter information could be the number of target tasks, which could be 3, and so on.
[0142] Therefore, based on the task type of the current task, the target task filtering information can be obtained from the preset relationship mapping table, and a location marker can be added to the set of tasks to be executed based on the target task filtering information.
[0143] In one embodiment, when the target task filtering information is the number of target tasks, and the number of tasks to be executed in the task set is less than the number of target tasks, a location marker can be added to the task to be executed last in the execution order of the task set.
[0144] For example, if the target number of tasks is 7, but there are only 4 tasks to be executed in the task set, then a location marker can be added to the last task in the task set that is to be executed.
[0145] In one embodiment, when the task filtering information is the type of the target task, the task type of the task to be executed can be matched with the task type of the target task. When the task type of the task to be executed matches the task type of the target task, a location identifier can be added to the task to be executed, and the task to be executed with the location identifier can be filtered out as the target task. Then, an asynchronous call waiting function is called at the task to be executed with the location identifier and at the end of the execution order.
[0146] In one embodiment, when creating a sub-loop thread for executing at least one target task using an asynchronous call function, an asynchronous call wait function can be used to trigger the task execution engine to create the sub-loop thread, and at least one target task can be added to the sub-loop thread for execution. Specifically, the step "creating a sub-loop thread for executing at least one target task using the asynchronous call function" includes:
[0147] The asynchronous call to the waiting function triggers the task execution engine to call the thread creation function to create a child loop thread.
[0148] The task execution engine includes a virtual machine that assigns tasks from the application to threads on a computer device for execution. Thread creation functions include functions that can create child loop threads.
[0149] In one embodiment, since each task in the application is essentially a computer program, and computer programs are usually written in a programming language, when the computer device executes the tasks in the application, the task execution engine can convert the programming language into a language that the computer device can recognize and allocate the tasks in the application to threads for execution.
[0150] The task execution engine can include the V8 engine or the JavaScript engine, etc. Furthermore, different task execution engines can have different thread creation functions.
[0151] For example, when the task execution engine is the V8 engine, a child loop thread can be created using "v8::platform::PumpMessageLoop".
[0152] For example, when the task execution engine is a JavaScript engine, CFRunLoopRun can be used to create a sub-loop thread.
[0153] In one embodiment, after creating a sub-loop thread, a target task can be added to the sub-loop thread so that the sub-loop thread executes at least one target task.
[0154] For example, such as Figure 7 The target task filtering information includes the number of target tasks, and the number of target tasks is 4. At this point, a location marker can be added at task 7 to be executed, and an asynchronous call waiting function can be invoked, so that the asynchronous call waiting function creates a sub-loop thread to execute tasks 1 through 4.
[0155] For example, such as Figure 8 The target task filtering information includes the type of the target task. After matching, it is found that the task types of task 1, task 4, and task 5 match the task types of the target task. At this point, location markers can be added to task 1, task 4, and task 5 respectively, and an asynchronous call waiting function can be called so that the asynchronous call waiting function creates a child loop thread to execute task 1, task 4, and task 5.
[0156] 104. Use a sub-loop thread to execute at least one target task.
[0157] After creating a child loop thread, you can use the child loop thread to execute at least one target task.
[0158] In one embodiment, before executing at least one target task using a sub-loop thread, the execution order of the target tasks in the set of tasks to be executed can be determined so that the sub-loop thread can execute at least one target task according to the execution order.
[0159] For example, the target tasks to be executed using a sub-loop thread include target task 1, target task 2, and target task 3. Target task 1 is the second task to be executed in the set of tasks to be executed, target task 2 is the third task, and target task 3 is the third task. The sub-loop thread then executes the target tasks according to their execution order in the set of tasks to be executed.
[0160] By having child loop threads execute target tasks in the order of execution, the tasks in the task set can still be executed in the order of execution, avoiding omissions or loss of tasks during the execution process, and improving the stability and robustness of task execution.
[0161] In one embodiment, during the execution of the target task using a sub-loop thread, if it is detected that the current task being executed by the sub-loop thread meets a preset triggering condition, an asynchronous call waiting function can also be called in the sub-loop thread so that the target task whose execution order is after the current task being executed by the sub-loop thread is executed.
[0162] 105. When it is detected that the asynchronous call waiting function has received the execution result of the current task, the task loop thread is triggered to execute the unexecuted tasks in the set of tasks to be executed based on the execution result.
[0163] Unexecuted tasks include tasks in the task set that have not yet been executed.
[0164] While the child loop thread is executing the target, the task loop thread is also executing the current task. When the asynchronous call waiting function detects that the current task has been completed, it means that the current task has been completed. At this point, the task loop thread can be triggered to execute the unexecuted tasks in the pending task set based on the execution result.
[0165] In one embodiment, since both the task loop thread and the sub-loop thread may contain unexecuted tasks, when it is detected that the asynchronous call waiting function has received the execution result of the current task, the execution status of the target task in the sub-loop thread can be checked first, and then the task loop thread can be triggered to execute the unexecuted tasks in the task set based on the execution status. Specifically, the step "when it is detected that the asynchronous call waiting function has received the execution result of the current task, trigger the task loop thread to execute the unexecuted tasks in the task set to be executed based on the execution result" includes:
[0166] When it is detected that the asynchronous call waiting function has received the execution result of the current task, the execution status of the target task in the sub-loop thread is checked to obtain the execution status of the target task;
[0167] The task loop thread is triggered based on the execution status to execute unexecuted tasks in the task set.
[0168] The execution status of the target task includes whether any of the target tasks in the sub-loop thread have been completed. For example, if the sub-loop thread contains four target tasks, and two of them have been completed, then those two target tasks are considered "completed." The other two target tasks are considered "incomplete." In this case, the incomplete tasks in the task set can be executed based on their execution status.
[0169] In one embodiment, when an unexecuted task is detected in the sub-loop thread, the execution order of the unexecuted tasks in the set of tasks to be executed can be determined, and then the task loop thread is triggered to execute the unexecuted tasks according to that execution order. Specifically, the step "triggering the task loop thread to execute unexecuted tasks in the task set according to the execution status" includes:
[0170] When an unexecuted task is detected in a sub-loop thread, the execution order of the unexecuted task in the set of tasks to be executed is determined;
[0171] The task loop thread is triggered based on the execution order to execute unexecuted tasks.
[0172] For example, such as Figure 9 As shown, in the sub-loop thread, tasks 1 and 2 have been executed, while tasks 3 and 4 have not. When an unexecuted task is detected in the sub-loop thread, the execution order of tasks 3 and 4 in the task set can be determined. After determining the execution order of tasks 3 and 4, the task loop thread can be triggered to execute the unexecuted tasks according to the execution order.
[0173] In one embodiment, when it is detected that the sub-loop thread does not include any unexecuted tasks, unexecuted tasks can be identified in the set of tasks to be executed, and then the task loop thread can be triggered to execute the unexecuted tasks. Specifically, the step "triggering the task loop thread to execute unexecuted tasks in the task set based on the execution status" may include:
[0174] When it is detected that there are no unexecuted tasks in the sub-loop thread, the unexecuted tasks are determined in the set of tasks to be executed;
[0175] Trigger the task loop thread to execute unexecuted tasks.
[0176] For example, such as Figure 10 As shown, the sub-loop thread has completed the execution of tasks 1, 2, 3, and 4. When it is detected that the sub-loop thread does not include any unexecuted tasks, the unexecuted tasks can be identified in the set of tasks to be executed. When the set of tasks to be executed includes tasks 5 to n, the task loop thread can be triggered to execute tasks 5 to n.
[0177] In one embodiment, when it is detected that the current task being executed by the task loop thread meets a preset trigger condition, the task execution status of the current task can be detected. When a change in task status is detected, an asynchronous notification function in the task loop thread can be called to obtain the execution result of the current task, and the execution result can be passed to the asynchronous call waiting function through the asynchronous notification function. Specifically, the asynchronous call method proposed in this application embodiment further includes:
[0178] When it is detected that the current task being executed by the task loop thread meets the preset triggering condition, the task execution status of the current task is detected;
[0179] When a change in the task execution status is detected, the asynchronous notification function in the task loop thread is called to obtain the execution result of the current task;
[0180] The execution result is passed to the asynchronous call waiting function through the asynchronous notification function.
[0181] The current task execution status includes the current execution state of the task. For example, the task execution status can include the current task completed, the current task not yet completed, and so on.
[0182] The asynchronous notification function includes functions that can obtain the execution result of the current task and pass the execution structure to the asynchronous call waiting function.
[0183] In one embodiment, the asynchronous notification function is also one of the functional functions of the asynchronous calling mechanism proposed in this application. The asynchronous notification function's role includes obtaining the execution result of the current task and passing the execution result to the asynchronous call waiting function.
[0184] In one embodiment, the asynchronous notification function can also be represented in various forms. For example, the asynchronous notification function can be represented by signal.notify(result), signal.inform(result), etc. The embodiments described in this application are not limited in scope. The result may include the execution result of the current task.
[0185] In one embodiment, when a change in the execution state of the current task is detected, an asynchronous notification function can be invoked to obtain the execution result of the current task. For example, when it is detected that the execution state of the current task has changed from not completed to completed, the asynchronous notification function can be invoked to obtain the execution result of the current task, and then the execution result can be passed to the asynchronous calling function through the asynchronous notification function.
[0186] The asynchronous notification function proposed in this application is intended to quickly pass the execution result of the current task to the asynchronous calling function, so that the task loop thread can be quickly triggered to execute the unexecuted tasks in the task set to be executed, thereby improving the execution efficiency of tasks in the application.
[0187] This application proposes an asynchronous invocation method, which includes: determining a set of tasks to be executed in an application, the set including at least one task to be executed in an order of execution; executing the tasks in the set using a task loop thread of the application; when it is detected that the current task being executed by the task loop thread meets a preset trigger condition, invoking an asynchronous invocation wait function of the task loop thread to create a sub-loop thread for executing at least one target task; executing the at least one target task using the sub-loop thread; and when it is detected that the asynchronous invocation wait function receives the execution result of the current task, triggering the task loop thread to execute unexecuted tasks in the set based on the execution result. The asynchronous invocation method proposed in this application allows for the continuation of subsequent tasks without waiting for the current task to finish or for the exception to be resolved, even when the current task takes a long time to execute or an exception occurs, thereby improving the execution efficiency of tasks in the application.
[0188] Furthermore, the asynchronous call waiting function in the asynchronous call method proposed in this application embodiment can be used at any location in any task of the application, so that the asynchronous call mechanism proposed in this application embodiment can be applied to various application scenarios and easily solve the problem that various applications will reduce the efficiency of task execution during the execution of tasks.
[0189] Based on the method described in the above embodiments, the following examples will provide further detailed explanations.
[0190] This application will use the integration of asynchronous call methods into a computer device as an example to illustrate the method of this application.
[0191] In one embodiment, such as Figure 11 As shown, an asynchronous method invocation process is described below:
[0192] 201. The computer device determines a set of tasks to be executed for an application, the set of tasks to be executed including at least one task to be executed in the order of execution.
[0193] For example, if an application has 20 unexecuted tasks in the current time period, the computer device can identify 10 tasks to be executed from these 20 unexecuted tasks and add these 10 tasks to the task set to be executed, so that these 10 tasks can be executed by the task loop thread.
[0194] 202. Computer devices utilize the task loop thread of the application to execute tasks in a set of pending tasks.
[0195] 203. When the computer device detects that the current task being executed by the task loop thread meets the preset triggering conditions, it calls the asynchronous call waiting function of the task loop thread to create a sub-loop thread for executing at least one target task. The target tasks include tasks in the task set to be executed that are executed after the current task.
[0196] In one embodiment, to improve task execution efficiency, this application proposes an asynchronous call mechanism, which can be represented by Signal. This Signal mechanism may include an asynchronous call to the wait function signal.wait().
[0197] In one embodiment, an asynchronous call creation function wx.createSignal() can also be created before the asynchronous call wait function is invoked, which indicates that a signal object has been created.
[0198] In one embodiment, when a computer device detects that the current task being executed by the task loop thread is blocked, it may invoke an asynchronous call wait function.
[0199] For example, such as Figure 12 As shown, when the computer device detects that the current task setTimeout() is blocked in the task loop thread, the computer device can suspend setTimeout() and call signal.wait() to allow the pending tasks doFoo1() and doFoo2() after setTimeout() to be executed.
[0200] 204. Computer devices use sub-loop threads to execute at least one target task.
[0201] 205. When the computer device detects that the asynchronous call waiting function has received the execution result of the current task, it triggers the task loop thread to execute the unexecuted tasks in the set of pending tasks based on the execution result.
[0202] In one embodiment, an asynchronous notification function (signal.notify(result)) can be called in the current task, and signal.notify(result) can be used to detect the task execution status of the current task. When the task execution status of the current task changes to task completion, signal.notify(result) will take the execution result of the current task, that is, the parameter result will become the execution result of the current task, and pass the execution result to the asynchronous call waiting function, so that the asynchronous call waiting function will trigger the task loop thread to execute the unexecuted tasks in the pending task set based on the execution result.
[0203] This application proposes an asynchronous invocation method. The method includes a computer device determining a set of tasks to be executed in an application, the set including at least one task to be executed in an execution order; the computer device using a task loop thread of the application to execute the tasks in the set; when it is detected that the current task being executed by the task loop thread meets a preset triggering condition, the computer device invoking an asynchronous invocation wait function of the task loop thread to create a sub-loop thread for executing at least one target task; the computer device using the sub-loop thread to execute at least one target task; and when it is detected that the asynchronous invocation wait function receives the execution result of the current task, the computer device triggers the task loop thread to execute unexecuted tasks in the set based on the execution result, thereby improving task execution efficiency.
[0204] In one embodiment, for example, the application is a mini-program, and the current task is to implement an asynchronous network request within the mini-program, such as... Figure 13 As shown. In Figure 13In the code, task `wx.request()` retrieves the network request, and the current task `success()` outputs the result of the network request. Since task `wx.request()` is an asynchronous network request, the current task `success()` can only execute after `wx.request()` returns data; it cannot execute quickly. Furthermore, existing asynchronous call methods cannot suspend the current task `success()`. However, in this implementation, `signal.wait()` and `signal.notify()` can be used to suspend the current task `success()`. For example, as... Figure 14 As shown, by using `signal.wait()` and `signal.notify()`, the current task `success()` is suspended, allowing the execution of other tasks in the pending task set to continue. When `signal.notify()` detects that `success()` has obtained a result, it passes the result to `signal.wait()`, allowing the task loop to continue executing the unexecuted tasks in the pending task set, thus improving task execution efficiency.
[0205] To better implement the detection method provided in the embodiments of this application, one embodiment also provides a testing and inspection device, which can be integrated into a computer device. The meanings of the terms used are the same as in the product testing and inspection method described above, and specific implementation details can be found in the description of the method embodiments.
[0206] In one embodiment, an asynchronous invocation device is provided, which can be specifically integrated into a computer device, such as... Figure 15 As shown, the testing and verification device includes: a determining unit 301, a first execution unit 302, a calling unit 303, a second execution unit 304, and a triggering unit 305, as detailed below:
[0207] The determining unit 301 is used to determine the set of tasks to be executed by the application, the set of tasks to be executed including at least one task to be executed in the order of execution;
[0208] The first execution unit 302 is used to execute the tasks to be executed in the task set using the task loop thread of the application.
[0209] Calling unit 303 is used to call the asynchronous call waiting function of the task loop thread when it is detected that the current task being executed by the task loop thread meets the preset triggering condition, so as to create a sub-loop thread for executing at least one target task. The target task includes the task to be executed in the task set whose execution order is after the current task.
[0210] The second execution unit 304 is used to execute at least one target task using the sub-loop thread;
[0211] The triggering unit 305 is used to trigger the task loop thread to execute the unexecuted tasks in the set of pending tasks based on the execution result when the asynchronous call waiting function receives the execution result of the current task.
[0212] In one embodiment, such as Figure 16 As shown, the calling unit 303 includes:
[0213] The determining subunit 3031 is used to determine the task type of the current task when it is detected that the current task being executed by the task loop thread meets the preset triggering condition;
[0214] Add subunit 3032, used to add a location identifier to the set of tasks to be executed according to the task type of the current task;
[0215] Subunit 3033 is invoked to invoke the asynchronous call waiting function of the task loop thread according to the location identifier, and to filter out at least one target task from the set of tasks to be executed according to the location identifier, so as to create a sub-loop thread for executing at least one target task using the asynchronous call waiting function.
[0216] In one embodiment, adding subunit 3032 may include:
[0217] The acquisition module is used to obtain target task filtering information from a preset relationship mapping table based on the task type of the current task;
[0218] An add module is used to add location identifiers to the set of tasks to be executed based on the target task filtering information.
[0219] In one embodiment, the calling subunit 3033 may include:
[0220] The triggering module is used to trigger the task execution engine to call the thread creation function to create the sub-loop thread using the asynchronous call waiting function.
[0221] In one embodiment, such as Figure 16 As shown, the triggering unit 305 includes:
[0222] The detection subunit 3051 is used to detect the execution status of the target task in the sub-loop thread when the asynchronous call waiting function receives the execution result of the current task, and to obtain the execution status of the target task.
[0223] Trigger subunit 3052 is used to trigger the task loop thread to execute the unexecuted tasks in the set of tasks to be executed according to the execution status.
[0224] In one embodiment, the trigger subunit 3052 includes:
[0225] The determination module is used to determine the execution order of the unexecuted tasks in the set of tasks to be executed when it is detected that the sub-loop thread includes unexecuted tasks;
[0226] The triggering module is used to trigger the task loop thread to execute the unexecuted tasks according to the execution order.
[0227] In practice, each of the above units can be implemented as an independent entity or can be arbitrarily combined to be implemented as the same or several entities. For the specific implementation of each of the above units, please refer to the previous method embodiments, which will not be repeated here.
[0228] The asynchronous calling mechanism described above allows subsequent tasks to continue execution without waiting for the current task to finish or the exception to be resolved, even if the current task takes a long time to execute or an exception occurs. This improves the execution efficiency of tasks in the application.
[0229] This application also provides a computer device, which may include a terminal or a server. For example, the computer device may serve as a testing and inspection terminal, such as a mobile phone, tablet computer, etc.; or it may serve as a server, such as a testing and inspection server. Figure 17 As shown, it illustrates the structural diagram of the terminal involved in the embodiments of this application, specifically:
[0230] The computer device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will understand that... Figure 17 The computer device structure shown does not constitute a limitation on the computer device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein:
[0231] The processor 401 is the control center of the computer device. It connects various parts of the computer device via various interfaces and lines, and performs various functions and processes data by running or executing software programs and / or modules stored in the memory 402, and by calling data stored in the memory 402, thereby providing overall monitoring of the computer device. Optionally, the processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user page, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 401.
[0232] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 402 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.
[0233] The computer device also includes a power supply 403 that supplies power to the various components. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 403 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0234] The computer device may also include an input unit 404, which can be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
[0235] Although not shown, the computer device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 401 in the computer device loads the executable files corresponding to the processes of one or more applications into the memory 402 according to the following instructions, and the processor 401 runs the applications stored in the memory 402 to realize various functions, as follows:
[0236] Determine a set of tasks to be executed for the application, the set of tasks to be executed including at least one task to be executed in the order of execution;
[0237] The task loop thread of the application is used to execute the tasks in the task set to be executed.
[0238] When it is detected that the current task being executed by the task loop thread meets the preset triggering condition, the asynchronous call waiting function of the task loop thread is called to create a sub-loop thread for executing at least one target task. The target task includes the task set to be executed, which is executed after the current task.
[0239] At least one target task is executed using the sub-loop thread;
[0240] When the asynchronous call waiting function is detected to have received the execution result of the current task, the task loop thread is triggered to execute the unexecuted tasks in the set of tasks to be executed based on the execution result.
[0241] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0242] According to one aspect of this application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in the various optional implementations of the above embodiments.
[0243] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by a computer program, or by a computer program controlling related hardware. The computer program can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0244] Therefore, embodiments of this application also provide a storage medium storing a computer program that can be loaded by a processor to execute the steps in any of the asynchronous calls provided in embodiments of this application. For example, the computer program can execute the following steps:
[0245] Determine a set of tasks to be executed for the application, the set of tasks to be executed including at least one task to be executed in the order of execution;
[0246] The task loop thread of the application is used to execute the tasks in the task set to be executed.
[0247] When it is detected that the current task being executed by the task loop thread meets the preset triggering condition, the asynchronous call waiting function of the task loop thread is called to create a sub-loop thread for executing at least one target task. The target task includes the task set to be executed, which is executed after the current task.
[0248] At least one target task is executed using the sub-loop thread;
[0249] When the asynchronous call waiting function is detected to have received the execution result of the current task, the task loop thread is triggered to execute the unexecuted tasks in the set of tasks to be executed based on the execution result.
[0250] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0251] Since the computer program stored in the storage medium can execute the steps in any of the asynchronous call methods provided in the embodiments of this application, the beneficial effects that any of the asynchronous call methods provided in the embodiments of this application can achieve can be realized, as detailed in the preceding embodiments, and will not be repeated here.
[0252] The above provides a detailed description of an asynchronous invocation method, apparatus, computer device, and readable storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. An asynchronous invocation method, characterized in that, The asynchronous invocation methods include: Determine a set of tasks to be executed for the application, the set of tasks to be executed including at least one task to be executed in the order of execution; The task loop thread of the application is used to execute the tasks in the task set to be executed. When it is detected that the current task being executed by the task loop thread meets the preset triggering condition, the asynchronous call waiting function of the task loop thread is called to create a sub-loop thread for executing at least one target task. The target task includes the task set to be executed, which is executed after the current task. At least one target task is executed using the sub-loop thread; When the asynchronous call waiting function is detected to have received the execution result of the current task, the task loop thread is triggered to execute the unexecuted tasks in the set of tasks to be executed based on the execution result.
2. The asynchronous invocation method as described in claim 1, characterized in that, When it is detected that the current task being executed by the task loop thread meets a preset trigger condition, the asynchronous call wait function of the task loop thread is invoked to create a sub-loop thread for executing at least one target task, including: When it is detected that the current task being executed by the task loop thread meets the preset triggering conditions, the task type of the current task is determined; Based on the task type of the current task, add a location identifier to the set of tasks to be executed; The asynchronous call waiting function of the task loop thread is invoked according to the location identifier, and at least one target task is selected from the set of tasks to be executed according to the location identifier, so as to create a sub-loop thread for executing at least one target task using the asynchronous call waiting function.
3. The asynchronous invocation method as described in claim 2, characterized in that, The step of adding a location identifier to the set of tasks to be executed according to the task type of the current task includes: Based on the task type of the current task, the target task filtering information is obtained from the preset relationship mapping table; Based on the target task filtering information, add location markers to the set of tasks to be executed.
4. The asynchronous invocation method as described in claim 2, characterized in that, The step of creating a sub-loop thread for executing at least one target task using the asynchronous function call includes: The asynchronous call waiting function triggers the task execution engine to call the thread creation function to create the sub-loop thread.
5. The asynchronous invocation method as described in claim 2, characterized in that, The method further includes: Determine the execution order of the at least one target task in the execution task set; The execution of at least one target task using the sub-loop thread includes: The sub-loop thread executes at least one target task according to the execution order.
6. The asynchronous invocation method as described in claim 1, characterized in that, When it is detected that the asynchronous call waiting function has received the execution result of the current task, the task loop thread is triggered to execute the unexecuted tasks in the set of pending tasks based on the execution result, including: When it is detected that the asynchronous call waiting function has received the execution result of the current task, the execution status of the target task in the sub-loop thread is checked to obtain the execution status of the target task; Based on the execution status, the task loop thread is triggered to execute the unexecuted tasks in the task set to be executed.
7. The asynchronous invocation method as described in claim 6, characterized in that, The step of triggering the task loop thread to execute the unexecuted tasks in the task set to be executed based on the execution status includes: When it is detected that the sub-loop thread includes unexecuted tasks, the execution order of the unexecuted tasks in the set of tasks to be executed is determined; The task loop thread is triggered according to the execution order to execute the unexecuted tasks according to the execution order.
8. The asynchronous invocation method as described in claim 6, characterized in that, The step of triggering the task loop thread to execute unexecuted tasks in the task set based on the execution status includes: When it is detected that no unexecuted tasks are included in the sub-loop thread, the unexecuted tasks are determined in the set of tasks to be executed. The task loop thread is triggered to execute the unexecuted task.
9. The asynchronous invocation method as described in claim 1, characterized in that, The method further includes: When it is detected that the current task being executed by the task loop thread meets the preset triggering condition, the task execution status of the current task is detected; When a change in the task execution status is detected, the asynchronous notification function in the task loop thread is called to obtain the execution result of the current task; The execution result is passed to the asynchronous call waiting function through the asynchronous notification function.
10. The asynchronous invocation method as described in claim 1, characterized in that, The method further includes: When it is detected that the current task being executed by the sub-loop thread meets the preset triggering condition, the asynchronous call waiting function of the sub-loop thread is called so that the target task whose execution order is after the current task being executed by the sub-loop thread is executed.
11. An asynchronous invocation device, characterized in that, The asynchronous invocation device includes: A determining unit is configured to determine a set of tasks to be executed by an application, the set of tasks to be executed including at least one task to be executed in an execution order; The first execution unit is used to execute the tasks in the task set to be executed using the task loop thread of the application. The calling unit is used to call the asynchronous call waiting function of the task loop thread when it is detected that the current task being executed by the task loop thread meets the preset triggering condition, so as to create a sub-loop thread for executing at least one target task. The target task includes the tasks in the task set to be executed that are executed after the current task. The second execution unit is used to execute at least one target task using the sub-loop thread; The triggering unit is used to trigger the task loop thread to execute the unexecuted tasks in the set of tasks to be executed based on the execution result when the asynchronous call waiting function receives the execution result of the current task.
12. A computer device, characterized in that, It includes a memory and a processor; the memory stores an application program, and the processor runs the application program within the memory to perform the operations in the asynchronous invocation method according to any one of claims 1 to 10.
13. A readable storage medium, characterized in that, The readable storage medium stores a plurality of instructions adapted for loading by a processor to execute the steps of the asynchronous invocation method according to any one of claims 1 to 10.