CN111679815B - Asynchronous operation method and device, storage medium and related equipment - Google Patents

Asynchronous operation method and device, storage medium and related equipment Download PDF

Info

Publication number
CN111679815B
CN111679815B CN202010502135.3A CN202010502135A CN111679815B CN 111679815 B CN111679815 B CN 111679815B CN 202010502135 A CN202010502135 A CN 202010502135A CN 111679815 B CN111679815 B CN 111679815B
Authority
CN
China
Prior art keywords
state
execution state
executing
execution
logic
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010502135.3A
Other languages
Chinese (zh)
Other versions
CN111679815A (en
Inventor
李春
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Shiyuan Electronics Thecnology Co Ltd
Guangzhou Shizhen Information Technology Co Ltd
Original Assignee
Guangzhou Shiyuan Electronics Thecnology Co Ltd
Guangzhou Shizhen Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangzhou Shiyuan Electronics Thecnology Co Ltd, Guangzhou Shizhen Information Technology Co Ltd filed Critical Guangzhou Shiyuan Electronics Thecnology Co Ltd
Priority to CN202010502135.3A priority Critical patent/CN111679815B/en
Publication of CN111679815A publication Critical patent/CN111679815A/en
Application granted granted Critical
Publication of CN111679815B publication Critical patent/CN111679815B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/313Logic programming, e.g. PROLOG programming language
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Retry When Errors Occur (AREA)

Abstract

The embodiment of the application discloses an asynchronous operation method and device, a storage medium and related equipment, and belongs to the technical field of computers. Wherein the method comprises the following steps: triggering and changing the execution state of the asynchronous object in the process of executing the main logic; after the execution state of the asynchronous object is changed, executing processing logic corresponding to the changed execution state; judging whether the modified execution state is a termination state or not; it is determined whether to continue executing the main logic based on the determination result. Therefore, the embodiment of the application can achieve the purposes of separating the main logic from the processing logic and modifying the execution state of the asynchronous object for multiple times, thereby realizing the technical effects of avoiding the occurrence of multi-layer nesting, improving the flexibility and adapting to more scenes, and further solving the technical problems of poor flexibility and small application range of the asynchronous operation method in the related technology.

Description

Asynchronous operation method and device, storage medium and related equipment
Technical Field
The present application relates to the field of computers, and in particular, to an asynchronous operation method and apparatus, a storage medium, and related devices.
Background
Currently, the asynchronous programming scheme of JavaScript mainly includes the following two kinds: the first method is a callback function mode, the callback function is taken as a parameter to be transmitted into and executed while asynchronous operation is executed, and related callback logic is actively called after the execution is successful, however, the first method has the problem of multi-layer nesting. The second is a promiscuous scheme, in which the asynchronous flow is managed by a promiscuous object, and the promiscuous object is a proxy object, which allows the corresponding processing methods to be respectively bound for success and failure of the asynchronous operation, so that the asynchronous operation can return a value like a synchronous operation, but not return a final execution result immediately, but a promiscuous object which can represent a result appearing in the future, thereby avoiding the problem of multi-layer nesting. The Promise object state includes three kinds, pending, full, failed, and the state change is unidirectional, and the state cannot be changed again when execution succeeds or fails.
In view of the above problems, no effective solution has been proposed at present.
Disclosure of Invention
The embodiment of the application provides an asynchronous operation method and device, a storage medium and related equipment, which are used for at least solving the technical problems of poor flexibility and small application range of the asynchronous operation method in the related technology.
According to one aspect of the embodiments of the present application, there is provided an asynchronous operation method, including: triggering and changing the execution state of the asynchronous object in the process of executing the main logic; after the execution state of the asynchronous object is changed, executing processing logic corresponding to the changed execution state; judging whether the modified execution state is a termination state or not; it is determined whether to continue executing the main logic based on the determination result.
Optionally, determining whether to continue executing the main logic based on the determination result includes: determining to stop executing the main logic in the case that the modified execution state is a termination state; in the event that the modified execution state is not a termination state, it is determined to continue executing the main logic.
Optionally, executing the processing logic corresponding to the modified execution state includes: executing success logic under the condition that the changed execution state is a success state; executing failure logic under the condition that the changed execution state is a failure state; and executing the termination logic when the modified execution state is the termination state.
Optionally, when execution of the main logic is started, the execution state of the asynchronous object is triggered to be changed to an executing state.
Optionally, after determining to continue executing the main logic, a change to the executing state of the asynchronous object to an executing state is triggered.
Optionally, before the main logic is executed, the method further comprises: constructing an asynchronous object and declaring main logic, wherein the asynchronous object is a main body of asynchronous operation; processing logic is declared.
According to another aspect of the embodiments of the present application, there is also provided an asynchronous operation device, including: the triggering module is used for triggering and changing the execution state of the asynchronous object in the process of executing the main logic; the execution module is used for executing processing logic corresponding to the execution state after the execution state of the asynchronous object is changed; the judging module is used for judging whether the changed execution state is a termination state or not; and the determining module is used for determining whether to continue executing the main logic or not based on the judging result.
Optionally, the determining module includes: a first determining unit configured to determine to stop executing the main logic in a case where the changed execution state is a termination state; and the second determining unit is used for determining to continue to execute the main logic in the case that the changed execution state is not the termination state.
According to another aspect of the embodiments of the present application, there is also provided a computer storage medium storing a plurality of instructions adapted to be loaded by a processor and to perform the above-described method steps.
According to another aspect of the embodiments of the present application, there is also provided an electronic device, including: a processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and to perform the method steps described above.
In the embodiment of the application, in the process of executing the main logic, the processing logic can be triggered by changing the state of the asynchronous object, and whether the main logic is continuously executed can be determined by judging whether the execution state is changed into the termination state, so that the purposes of separating the main logic from the processing logic and modifying the execution state of the asynchronous object for multiple times are achieved, the situation of multi-layer nesting is avoided, the flexibility is improved, the technical effect of adapting to more scenes is achieved, and the technical problems of poor flexibility and small application range of an asynchronous operation method in the related art are solved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiments of the application and together with the description serve to explain the application and do not constitute an undue limitation to the application. In the drawings:
FIG. 1 is a flow chart of a method of asynchronous operation according to an embodiment of the present application;
FIG. 2 is a schematic diagram of another asynchronous method of operation according to an embodiment of the present application;
FIG. 3 is a schematic diagram of an alternative asynchronous method of operation according to an embodiment of the present application;
FIG. 4 is a schematic diagram of an asynchronous operation device according to an embodiment of the present application; and
fig. 5 is a schematic diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In order to make the present application solution better understood by those skilled in the art, the following description will be made in detail and with reference to the accompanying drawings in the embodiments of the present application, it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art based on the embodiments herein without making any inventive effort, shall fall within the scope of the present application.
When the following description refers to the accompanying drawings, the same numbers in different drawings refer to the same or similar elements, unless otherwise indicated. The implementations described in the following exemplary examples are not representative of all implementations consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present application as detailed in the accompanying claims.
It should be noted that the terms "first," "second," and the like in the description and claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that embodiments of the present application described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus. Furthermore, in the description of the present application, unless otherwise indicated, "a plurality" means two or more. "and/or", describes an association relationship of an association object, and indicates that there may be three relationships, for example, a and/or B, and may indicate: a exists alone, A and B exist together, and B exists alone. The character "/" generally indicates that the context-dependent object is an "or" relationship.
Example 1
The embodiment of the application provides an asynchronous operation method, which is applied to electronic equipment, such as a computer terminal, a smart phone, a tablet computer and the like, but is not limited thereto, and the application is not particularly limited thereto.
FIG. 1 is a flow chart of a method of asynchronous operation, as shown in FIG. 1, according to an embodiment of the present application, the method comprising the steps of:
step S102, triggering and changing the execution state of an asynchronous object in the process of executing the main logic;
the main logic in the above steps may refer to the main processing logic in asynchronous operation. The asynchronous object may be a main body of the asynchronous operation, and controls the flow and state change of the asynchronous operation, and is similar to the promiscuous object, and is a proxy object, which allows the corresponding processing methods (handles) to be respectively bound for success, failure and termination of the asynchronous operation.
In the embodiment of the present application, the execution states of the asynchronous object include four types, which are an executing state, a success state, a failure state, and a termination state. The master logic may perform synchronous or asynchronous operations during execution and may trigger a change in execution state.
In an alternative embodiment, in the process of executing the main logic, when the asynchronous operation needs to be executed, the main logic can call the asynchronous object to change the execution state into the executing state, so that the asynchronous object starts to execute the asynchronous operation, and the purpose of triggering to change the execution state of the asynchronous object is achieved.
For example, taking the caching scheme of user network requests as an example, the main logic may perform the following operations: receiving a network request initiated by a user network, and returning a request result corresponding to the network request or prompting information that the request result cannot be queried to the user network; asynchronous operations may perform the following: and obtaining a request result corresponding to the network request, and caching the request result in a local area. On the basis, the main logic can continuously receive the network request, after each time of receiving the network request, firstly checking whether the state of the asynchronous object is the executing state, if not, changing the state of the asynchronous object into the executing state, and acquiring and caching the request result of the network request by the asynchronous object; if yes, the network request is stored in the task list, after the execution state of the asynchronous object is changed into the non-execution state, the state of the asynchronous object is changed into the execution state, and the request result of the first network request in the task list is obtained by the asynchronous object and is cached.
Step S104, after the execution state of the asynchronous object is changed, executing processing logic corresponding to the changed execution state;
in this embodiment of the present application, different processing logic may be bound in advance for different execution states, and specifically, corresponding processing logic may be bound for three states, such as a success state, a failure state, and a termination state. On this basis, after detecting the execution state change, processing logic corresponding to the changed execution state may be executed.
In an alternative embodiment, the execution state of the asynchronous object may be changed by the main logic when the asynchronous object is invoked, or may be changed automatically by the asynchronous object based on the execution result of the asynchronous operation. After the execution state is changed to the success state, the master logic may execute the success logic corresponding to the success state; after the execution state is changed to the failure state, the master logic may execute the failure logic corresponding to the success state; after the execution state changes to the termination state, the master logic may execute termination logic corresponding to the termination state.
For example, taking a caching scheme of a user network request as an example, if the asynchronous object successfully acquires and caches a request result of the network request, the asynchronous object can change its execution state into a successful state, and further, the main logic can execute corresponding successful logic based on the successful state, that is, acquire the request result from the cache and return the request result to the user network; if the request result is not obtained, the asynchronous object can change the execution state of the asynchronous object into a failure state, and further, the main logic can execute corresponding failure logic based on the failure state, namely, prompt information which can not inquire the request result is returned to the user network; if the asynchronous operation is terminated, the asynchronous object may change its execution state to a termination state, and further, the master logic may execute the corresponding termination logic, i.e., the master logic stops receiving network requests sent by the user network.
Step S106, judging whether the modified execution state is a termination state;
step S108, determining whether to continue executing the main logic based on the judging result.
In an alternative embodiment, after the execution state is changed, it needs to be determined whether the execution state is changed to the termination state, and further whether to continue to execute the main logic is determined, where if the execution state is changed to the termination state, it may be determined that the main logic performs the termination operation, and the execution of the main logic is stopped, otherwise, the execution of the main logic may be continued, and the execution state of the asynchronous object may also be continued to be changed.
In the embodiment of the application, in the process of executing the main logic, the processing logic can be triggered by changing the state of the asynchronous object, and whether the main logic is continuously executed can be determined by judging whether the execution state is changed into the termination state, so that the purposes of separating the main logic from the processing logic and modifying the execution state of the asynchronous object for multiple times are achieved, the situation of multi-layer nesting is avoided, the flexibility is improved, the technical effect of adapting to more scenes is achieved, and the technical problems of poor flexibility and small application range of an asynchronous operation method in the related art are solved.
Example 2
As shown in fig. 2, the method comprises the steps of:
step S202, constructing an asynchronous object and declaring main logic, wherein the asynchronous object is a main body of asynchronous operation;
the main logic in the steps can be executed by one thread, and the asynchronous operation can be executed by the other thread, so that the execution of the asynchronous operation does not block the thread of the main logic and does not influence the normal execution of the main logic.
In an exemplary embodiment of the present invention, before performing the asynchronous operation, the asynchronous object may be constructed and the main logic may be declared at the same time, so as to initialize the asynchronous object and the main logic.
Step S204, declaring processing logic;
in an exemplary embodiment of the present invention, callback logic of this asynchronous operation may be declared by way of a function call, where the callback logic mainly includes three types: the system comprises success logic, failure logic and termination logic, wherein the success logic is callback logic triggered when the normal execution of the main logic is completed; the failure logic is callback logic triggered when the main logic executes exception; the termination logic is callback logic triggered when the main logic executes termination operation.
Step S206, when the execution of the main logic is started, triggering to change the execution state of the asynchronous object into the execution state;
in one exemplary embodiment of the present invention, execution of the main logic is started, at which time the execution state of the asynchronous object changes to an executing state.
In an alternative embodiment, execution of the main logic is initiated, and the execution state of the asynchronous object may be modified in the main logic to change the execution state to an in-execution state.
For example, taking the caching scheme of the user network request as an example, the main logic starts to receive the network request sent by the user network, at this time, the execution state of the asynchronous object may be changed to the executing state, so as to wait for the main logic to transmit the network request, and after receiving the network request, obtain the corresponding request result and cache.
Step S208, triggering and changing the execution state of the asynchronous object in the process of executing the main logic;
step S210, after the execution state of the asynchronous object is changed, executing processing logic corresponding to the changed execution state;
in the embodiment of the present application, the above steps may be specifically implemented by the following manner: executing success logic, namely triggering successful processing logic, under the condition that the changed execution state is the success state; executing failure logic, namely, triggering failed processing logic under the condition that the changed execution state is a failure state; in case the modified execution state is a termination state, the termination logic, i.e. the processing logic triggering the termination operation, is executed.
The processing logic in the above steps may be a processing function determined based on an execution function of the main logic, and the main logic may implement the purpose of executing the processing logic by calling the processing function after determining the execution state change of the asynchronous object. For example, taking a caching scheme of the user network request as an example, the success logic may be that the main logic obtains a request result corresponding to the network request sent by the user network from the cache, and returns the request result to the user network; the failure logic may be that the main logic does not acquire the request result from the cache, and at this time, prompt information that the request result cannot be queried may be returned to the user network; the termination logic may be a network request that the master logic stops receiving from the user network.
Step S212, judging whether the modified execution state is a termination state;
step S214, determining to stop executing the main logic when the modified execution state is a termination state;
in one exemplary embodiment of the present invention, after changing the state of the asynchronous object to a termination state, termination logic may be executed, and modifying the execution state in any logic will not take effect and throw an error, and the associated processing logic will not execute. That is, when the changed execution state is the termination state, the execution state of the asynchronous object is prohibited from being changed, and error information is output.
Step S216, determining to continue executing the main logic in the case that the modified execution state is not the termination state;
in an exemplary embodiment of the present invention, when the execution state is not a termination state, the execution state of the asynchronous state may be changed multiple times, each change triggering corresponding processing logic.
In step S218, after determining to continue executing the main logic, the execution state of the asynchronous object is triggered to be changed to the executing state.
In an exemplary embodiment of the present invention, when the execution state is not the termination state, the execution state of the asynchronous object may be changed to the in-execution state, for example, after the execution state is changed to the failure state, the execution state may be changed to the in-execution state again.
It should be noted that, for the sake of brevity, not all embodiments described in the present application are exhaustive, but all the features not inconsistent with each other can be freely combined to form the optional embodiments of the present application.
In the above embodiment of the present application, in the process of executing the main logic, by changing the execution state of the asynchronous object, different processing logics are triggered, so as to achieve the purposes of separating the main logic from the processing logic and modifying the execution state of the asynchronous object multiple times, thereby avoiding the occurrence of the situation of multi-layer nesting, improving the flexibility, and adapting to more scenes.
Example 3
The asynchronous operation method provided by the embodiment of the application can be applied to electronic equipment, and as shown in fig. 3, the method can comprise the following steps: initializing an asynchronous object and main logic; initializing processing logic; executing the main logic; changing the execution state of the asynchronous object; and executing corresponding processing logic and returning to continue to execute the main logic under the condition that the execution state is not the termination state, and triggering the termination logic and stopping executing the main logic under the condition that the execution state is the termination state.
Compared with a callback function mode, the asynchronous operation method provided by the embodiment of the application can better separate the main logic and the processing logic, and meanwhile, the condition that callback functions are nested in multiple layers is avoided; compared with the Promise scheme, the asynchronous object has more execution states (in execution, successful, failed and terminated), and the circulation among the execution states is non-unidirectional, so that the asynchronous object is more flexible and can adapt to more scenes.
For example, in a user network request caching scheme, the network request may be encapsulated using the scheme described above, and after the user initiates the network request, the request result may be stored in the cache, and at the next request: first, data can be obtained from the cache and success logic is executed, at which point the user can immediately view the cached data. After that, the user initiates a network request to acquire the latest data, after the latest data is acquired, the execution state of the asynchronous object can be changed into a successful state again, and the latest data can be displayed to the user by calling the successful logic again to process the latest data.
Example 4
The following are device embodiments of the present application, which may be used to perform method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.
Referring to fig. 4, a schematic structural diagram of an asynchronous operation device according to an exemplary embodiment of the present application is shown. The asynchronous operator may be implemented as all or part of the electronic device by software, hardware, or a combination of both. The apparatus includes a triggering module 42, an executing module 44, a judging module 46, and a determining module 48.
A triggering module 42, configured to trigger, during execution of the main logic, changing an execution state of the asynchronous object;
an execution module 44, configured to, after the execution state of the asynchronous object is changed, execute processing logic corresponding to the changed execution state;
a judging module 46, configured to judge whether the modified execution state is a termination state;
a determining module 48, configured to determine whether to continue executing the main logic based on the determination result.
On the basis of the above embodiment, the determining module includes: a first determining unit configured to determine to stop executing the main logic in a case where the changed execution state is a termination state; and the second determining unit is used for determining to continue to execute the main logic in the case that the changed execution state is not the termination state.
On the basis of the above embodiment, the execution module includes: the first execution unit is used for executing success logic under the condition that the changed execution state is a success state; the second execution unit is used for executing the failure logic under the condition that the changed execution state is the failure state; and the third execution unit is used for executing the termination logic when the changed execution state is the termination state.
On the basis of the embodiment, the triggering module is further configured to trigger, when the execution of the main logic is started, to change the execution state of the asynchronous object to the in-execution state.
On the basis of the embodiment, the triggering module is further configured to trigger changing the execution state of the asynchronous object to an executing state after determining to continue to execute the main logic.
On the basis of the embodiment, the device further comprises: the first initialization module is used for constructing an asynchronous object and declaring main logic, wherein the asynchronous object is a main body of asynchronous operation; and the second initialization module is used for declaring the processing logic.
It should be noted that, when the asynchronous operation device provided in the above embodiment performs the asynchronous operation method, only the division of the above functional modules is used as an example, in practical application, the above functional allocation may be performed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to perform all or part of the functions described above. In addition, the asynchronous operation device and the asynchronous operation method provided in the above embodiments belong to the same concept, which embody the detailed implementation process in the method embodiments, and are not described herein again.
Example 5
The embodiments of the present application further provide a computer storage medium, where a plurality of instructions may be stored, where the instructions are adapted to be loaded by a processor and execute the method steps of the embodiments shown in fig. 1 to 3, and the specific execution process may refer to the specific description of the embodiments shown in fig. 1 to 3, which is not repeated herein.
The device on which the storage medium resides may be an electronic device.
Example 6
As shown in fig. 5, the electronic device 1000 may include: at least one processor 1001, at least one network interface 1004, a user interface 1003, a memory 1005, at least one communication bus 1002.
Wherein the communication bus 1002 is used to enable connected communication between these components.
The user interface 1003 may include a Display screen (Display) and a Camera (Camera), and the optional user interface 1003 may further include a standard wired interface and a wireless interface.
The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface), among others.
Wherein the processor 1001 may include one or more processing cores. The processor 1001 connects various parts within the overall electronic device 1000 using various interfaces and lines, performs various functions of the electronic device 1000 and processes data by executing or executing instructions, programs, code sets, or instruction sets stored in the memory 1005, and invoking data stored in the memory 1005. Alternatively, the processor 1001 may be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), programmable logic array (Programmable Logic Array, PLA). The processor 1001 may integrate one or a combination of several of a central processing unit (Central Processing Unit, CPU), an image processor (Graphics Processing Unit, GPU), and a modem, etc. The CPU mainly processes an operating system, a user interface, an application program and the like; the GPU is used for rendering and drawing the content required to be displayed by the display screen; the modem is used to handle wireless communications. It will be appreciated that the modem may not be integrated into the processor 1001 and may be implemented by a single chip.
The Memory 1005 may include a random access Memory (Random Access Memory, RAM) or a Read-Only Memory (Read-Only Memory). Optionally, the memory 1005 includes a non-transitory computer readable medium (non-transitory computer-readable storage medium). The memory 1005 may be used to store instructions, programs, code, sets of codes, or sets of instructions. The memory 1005 may include a stored program area and a stored data area, wherein the stored program area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing the above-described respective method embodiments, etc.; the storage data area may store data or the like referred to in the above respective method embodiments. The memory 1005 may also optionally be at least one storage device located remotely from the processor 1001. As shown in fig. 5, an operating system, a network communication module, a user interface module, and an operating application of the electronic device may be included in the memory 1005, which is one type of computer storage medium.
In the electronic device 1000 shown in fig. 5, the user interface 1003 is mainly used for providing an input interface for a user, and acquiring data input by the user; and the processor 1001 may be configured to invoke an operating application of the electronic device stored in the memory 1005, and specifically perform the following operations:
triggering and changing the execution state of the asynchronous object in the process of executing the main logic; after the execution state of the asynchronous object is changed, executing processing logic corresponding to the changed execution state; judging whether the modified execution state is a termination state or not; it is determined whether to continue executing the main logic based on the determination result.
In one embodiment, the processor 1001 further performs the steps of:
determining to stop executing the main logic in the case that the modified execution state is a termination state; in the event that the modified execution state is not a termination state, it is determined to continue executing the main logic.
In one embodiment, the processor 1001 further performs the steps of:
executing success logic under the condition that the changed execution state is a success state; executing failure logic under the condition that the changed execution state is a failure state; and executing the termination logic when the modified execution state is the termination state.
In one embodiment, the processor 1001 further performs the steps of:
when the execution of the main logic is started, the execution state of the asynchronous object is triggered to be changed into the execution state.
In one embodiment, the processor 1001 further performs the steps of:
after determining to continue executing the main logic, a change to the executing state of the asynchronous object to an executing state is triggered.
In one embodiment, the processor 1001 further performs the steps of:
constructing an asynchronous object and declaring the main logic before the main logic is executed, wherein the asynchronous object is the main body of asynchronous operation; processing logic is declared.
In the embodiment of the application, in the process of executing the main logic, the processing logic can be triggered by changing the state of the asynchronous object, and whether the main logic is continuously executed can be determined by judging whether the execution state is changed into the termination state, so that the purposes of separating the main logic from the processing logic and modifying the execution state of the asynchronous object for multiple times are achieved, the situation of multi-layer nesting is avoided, the flexibility is improved, the technical effect of adapting to more scenes is achieved, and the technical problems of poor flexibility and small application range of an asynchronous operation method in the related art are solved.
It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In one typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include volatile memory in a computer-readable medium, random Access Memory (RAM) and/or nonvolatile memory, etc., such as Read Only Memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
Computer readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of storage media for a computer include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium, which can be used to store information that can be accessed by a computing device. Computer-readable media, as defined herein, does not include transitory computer-readable media (transmission media), such as modulated data signals and carrier waves.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or apparatus that comprises an element.
The foregoing is merely exemplary of the present application and is not intended to limit the present application. Various modifications and changes may be made to the present application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc. which are within the spirit and principles of the present application are intended to be included within the scope of the claims of the present application.

Claims (10)

1. A method of asynchronous operation, comprising:
triggering and changing the execution state of an asynchronous object in the process of executing the main logic, wherein the execution state of the asynchronous object comprises an executing state, a success state, a failure state and a termination state, and the execution state of the asynchronous object is changed when the main logic calls the asynchronous object or is automatically changed by the asynchronous object based on the execution result of the asynchronous operation;
after the execution state of the asynchronous object is changed, executing processing logic corresponding to the changed execution state;
judging whether the modified execution state is a termination state or not;
and determining whether to continue executing the main logic or not based on a judgment result, wherein when the changed execution state is a termination state, the execution state of the asynchronous object is prohibited from being changed, and when the execution state is not the termination state, the execution state of the asynchronous object is changed for a plurality of times, and each change triggers corresponding processing logic.
2. The method of claim 1, wherein determining whether to continue executing the main logic based on the determination result comprises:
determining to stop executing the main logic if the modified execution state is the termination state;
and if the changed execution state is not the termination state, determining to continue executing the main logic.
3. The method of claim 1, wherein executing the processing logic corresponding to the altered execution state comprises:
executing success logic under the condition that the changed execution state is a success state;
executing failure logic under the condition that the changed execution state is a failure state;
and executing termination logic under the condition that the modified execution state is the termination state.
4. A method according to claim 3, wherein when execution of the main logic is started, a change of the execution state of the asynchronous object to an executing state is triggered.
5. The method of claim 1, wherein after determining to continue executing the main logic, triggering a change of an execution state of the asynchronous object to an executing state.
6. The method of claim 1, wherein prior to execution of the main logic, the method further comprises:
constructing the asynchronous object and declaring the main logic, wherein the asynchronous object is a main body of asynchronous operation;
the processing logic is declared.
7. An asynchronous operation device, characterized by comprising:
the trigger module is used for triggering and changing the execution state of the asynchronous object in the process of executing the main logic, wherein the execution state of the asynchronous object comprises an executing state, a success state, a failure state and a termination state, and the execution state of the asynchronous object is changed when the main logic calls the asynchronous object or is automatically changed by the asynchronous object based on the execution result of the asynchronous operation;
the execution module is used for executing processing logic corresponding to the execution state after the execution state of the asynchronous object is changed;
the judging module is used for judging whether the modified execution state is a termination state or not;
the determining module is used for determining whether to continue executing the main logic or not based on the judging result, wherein the execution state of the asynchronous object is forbidden to be changed under the condition that the changed execution state is a termination state; in the event that the execution state is not a termination state, the execution state of the asynchronous object is changed multiple times, and each change triggers corresponding processing logic.
8. The apparatus of claim 7, wherein the means for determining comprises:
a first determining unit configured to determine to stop executing the main logic in a case where the changed execution state is the termination state;
and a second determining unit configured to determine to continue executing the main logic in a case where the modified execution state is not the termination state.
9. A computer storage medium storing a plurality of instructions adapted to be loaded by a processor and to perform the method steps of any of claims 1 to 6.
10. An electronic device, comprising: a processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and to perform the method steps of any of claims 1 to 6.
CN202010502135.3A 2020-06-04 2020-06-04 Asynchronous operation method and device, storage medium and related equipment Active CN111679815B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010502135.3A CN111679815B (en) 2020-06-04 2020-06-04 Asynchronous operation method and device, storage medium and related equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010502135.3A CN111679815B (en) 2020-06-04 2020-06-04 Asynchronous operation method and device, storage medium and related equipment

Publications (2)

Publication Number Publication Date
CN111679815A CN111679815A (en) 2020-09-18
CN111679815B true CN111679815B (en) 2024-02-09

Family

ID=72434858

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010502135.3A Active CN111679815B (en) 2020-06-04 2020-06-04 Asynchronous operation method and device, storage medium and related equipment

Country Status (1)

Country Link
CN (1) CN111679815B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4740891A (en) * 1985-05-06 1988-04-26 Tektronix, Inc. Asynchronous state machine
CN102929823A (en) * 2012-09-08 2013-02-13 佳都新太科技股份有限公司 Multiple serial port communication system and method based on thread pool
CN103514295A (en) * 2013-10-10 2014-01-15 中国电子科技集团公司第十五研究所 Method and device for archiving historical data
CN104484456A (en) * 2014-12-29 2015-04-01 哈尔滨工业大学 Multi-threading parallel-based rapid loading method for SQLite database

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4740891A (en) * 1985-05-06 1988-04-26 Tektronix, Inc. Asynchronous state machine
CN102929823A (en) * 2012-09-08 2013-02-13 佳都新太科技股份有限公司 Multiple serial port communication system and method based on thread pool
CN103514295A (en) * 2013-10-10 2014-01-15 中国电子科技集团公司第十五研究所 Method and device for archiving historical data
CN104484456A (en) * 2014-12-29 2015-04-01 哈尔滨工业大学 Multi-threading parallel-based rapid loading method for SQLite database

Also Published As

Publication number Publication date
CN111679815A (en) 2020-09-18

Similar Documents

Publication Publication Date Title
US20190324772A1 (en) Method and device for processing smart contracts
CN107656759B (en) Rendering method and device for user interface
JP6995780B2 (en) Application startup method and system
CN111249744B (en) Resource loading method and device, storage medium and electronic device
WO2016191610A1 (en) Method and apparatus for real-time data migration
CN108134766A (en) A kind of method, apparatus, system, server and client for servicing publication
CN112386916A (en) Resource loading method and device and electronic equipment
CN110362356B (en) Function data processing method and device, computer equipment and storage medium
CN111124544A (en) Interface display method and device, electronic equipment and storage medium
CN111679815B (en) Asynchronous operation method and device, storage medium and related equipment
CN111294377A (en) Network request sending method of dependency relationship, terminal device and storage medium
CN107797843B (en) Method and device for enhancing function of container
US9628401B2 (en) Software product instance placement
CN108804088B (en) Protocol processing method and device
CN108197029B (en) Method and device for acquiring process information
CN113127775A (en) Page loading method, device, equipment and storage medium
CN112559050A (en) Method and device for processing concurrency number of client asynchronous request information
CN111367577A (en) Method, device and terminal for loading plug-in of application
CN106445595B (en) Method and device for constructing Application object of plug-in
CN112416555B (en) Client restarting method, device and apparatus, and storage medium
CN115878916A (en) Time-consuming optimization method and device for page refreshing and terminal equipment
CN109150993B (en) Method for obtaining network request tangent plane, terminal device and storage medium
CN110083539B (en) Data competition detection method and device
CN109408147B (en) Protocol determination method, system, device and readable storage medium
CN111124931B (en) Java code compliance checking method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant