CN109669720B - Chain type asynchronous request processing method and device based on Promise and electronic equipment - Google Patents

Chain type asynchronous request processing method and device based on Promise and electronic equipment Download PDF

Info

Publication number
CN109669720B
CN109669720B CN201811394545.XA CN201811394545A CN109669720B CN 109669720 B CN109669720 B CN 109669720B CN 201811394545 A CN201811394545 A CN 201811394545A CN 109669720 B CN109669720 B CN 109669720B
Authority
CN
China
Prior art keywords
asynchronous
task
promise
memory
request
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
CN201811394545.XA
Other languages
Chinese (zh)
Other versions
CN109669720A (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.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network 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 Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN201811394545.XA priority Critical patent/CN109669720B/en
Publication of CN109669720A publication Critical patent/CN109669720A/en
Application granted granted Critical
Publication of CN109669720B publication Critical patent/CN109669720B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/466Transaction processing

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the invention provides a chain type asynchronous request processing method and device based on Promise and electronic equipment, belonging to the technical field of data processing, wherein the method comprises the following steps: acquiring all Promise-based asynchronous requests; registering an asynchronous event corresponding to the Promise-based asynchronous request in a memory through a custom commit grammar; calling the constructed asynchronous task manager to enable the asynchronous task manager to be packaged in a plurality of asynchronous tasks registered in a memory in a parallel mode; and transmitting the ID and the sequence number of the asynchronous event recorded in the source file to the asynchronous task manager, and executing the asynchronous request with the chain relation in the task manager in a parallel mode. By the processing scheme, the asynchronous task is more urgent and is beneficial to execution and maintenance.

Description

Chain type asynchronous request processing method and device based on Promise and electronic equipment
Technical Field
The invention relates to the technical field of data processing, in particular to a chain type asynchronous request processing method and device based on Promise and electronic equipment.
Background
In recent years, with the widespread use of internet technology, there has been an increasing demand for more and more users to browse content described by a markup language such as HTML on a computer device such as a computer, a smart device, or the like. Http (hyper Text Transfer protocol), a hypertext Transfer protocol, is a stateless, unidirectional protocol. An HTTP request is sent to the server, which accepts the request and processes it, and sends a response back after it is completed, and the client and server need to maintain the HTTP connection during the server's processing.
In order to adapt to the situation that a plurality of HTTP requests exist on a webpage and improve the response of the webpage, the HTTP asynchronous requests can be processed in an HTTP asynchronous request mode, and the asynchronous requests can return HTTP asynchronous request response results in a short polling mode. And the HTTP asynchronous request response result is returned in a short polling mode, and a new request is submitted to the server at regular time to realize the loading of data, so that the real-time effect is poor. Especially for asynchronous tasks with multiple dependencies, a cyclic dependency exists among multiple asynchronous tasks, that is, the execution of a subsequent asynchronous task depends on the execution result of a previous asynchronous task. Thereby resulting in a slower execution efficiency of the asynchronous task.
In JavaScript, code is executed in a single threaded manner. Due to this property of JavaScript, all web operations, browser events, that result in JavaScript must be executed asynchronously. Asynchronous execution is realized by a callback function. Very many callback nestings may occur sometimes, making the code hierarchy particularly deep, which is detrimental to code maintenance and migration.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method, an apparatus, and an electronic device for processing chained asynchronous requests based on Promise, which at least partially solve the problems in the prior art.
In a first aspect, an embodiment of the present invention provides a chained asynchronous request processing method based on Promise, including:
acquiring all Promise-based asynchronous requests;
registering an asynchronous event corresponding to the Promise-based asynchronous request in a memory through a custom commit grammar;
calling the constructed asynchronous task manager to enable the asynchronous task manager to be packaged in a plurality of asynchronous tasks registered in a memory in a parallel mode;
and transmitting the ID and the sequence number of the asynchronous event recorded in the source file to the asynchronous task manager, and executing the asynchronous request with the chain relation in the task manager in a parallel mode.
According to a specific implementation manner of the embodiment of the present invention, the acquiring all the Promise-based asynchronous requests includes:
acquiring display content on a current page;
judging whether the display content has a plurality of content sources;
if so, a Promise-based asynchronous request is determined based on the plurality of content sources.
According to a specific implementation manner of the embodiment of the present invention, the determining a Promise-based asynchronous request based on a plurality of content sources includes:
searching a plurality of content requests corresponding to the plurality of content sources;
a content request based on a content having a chained asynchronous request relationship is selected from the plurality of content requests as a Promise-based asynchronous request.
According to a specific implementation manner of the embodiment of the present invention, registering, in the memory, the asynchronous event corresponding to the Promise-based asynchronous request through the custom commit syntax includes:
receiving a character string parameter by setting a commit function;
searching a running task with the same parameters as the character strings in an addressing memory in a character string matching mode;
and selecting an asynchronous task meeting the conditions from the running tasks with the same character string parameters for registration.
According to a specific implementation manner of the embodiment of the present invention, selecting an asynchronous task meeting the condition from the running tasks having the same parameter as the character string to register includes:
judging whether the running task with the same character string parameter is an asynchronous task or not;
if so, executing the current task under the condition that the called asynchronous task does not exist at present, and searching whether a task set which is temporarily stored and is not called exists in a memory or not after the execution is finished;
if the temporary and un-called task set is stored in the memory after the execution is finished, the current process is called and repeated, if the task currently being called exists, the un-called task set is stored in the asynchronous task calling set, and the calling is carried out after the current execution task is finished.
According to a specific implementation manner of the embodiment of the present invention, the selecting an asynchronous task meeting the condition from the running tasks having the same parameter as the character string to register further includes:
when all the asynchronous tasks are called, further judging whether global error processing or successful processing exists when the current calling is finished;
if yes, returning an error result, otherwise, directly returning a processing result.
According to a specific implementation manner of the embodiment of the present invention, the constructing an asynchronous task manager to enable the asynchronous task manager to encapsulate a plurality of asynchronous tasks registered in a memory in a parallel manner includes:
registering the asynchronous tasks required to be used in the memory in advance;
encapsulating the asynchronous task through a frame to ensure that the task in the execution process conforms to the format of the Promise asynchronous specification in the frame;
the registration is completed when the asynchronous task is initialized at the framework.
According to a specific implementation manner of the embodiment of the present invention, the constructing an asynchronous task manager to enable the asynchronous task manager to encapsulate a plurality of asynchronous tasks registered in a memory in a parallel manner further includes:
receiving the name, sequence, state and concurrency information of calling asynchronous tasks in the calling process of the asynchronous task manager;
the decision of the dynamic according to the current execution state is to execute the next task or return the result.
According to a specific implementation manner of the embodiment of the present invention, the executing, in the task manager, the asynchronous request having a chain relation in a parallel manner includes:
synchronously registering all asynchronous events to be executed through commit grammar;
and setting an asynchronous event executor used for executing each asynchronous event inside the framework of the task manager, wherein the asynchronous event executor executes the callback of the Promise according to the state of the asynchronous event.
In a second aspect, an embodiment of the present invention provides a chained asynchronous request processing apparatus based on Promise, including:
the acquisition module is used for acquiring all the Promise-based asynchronous requests;
the registration module is used for registering the asynchronous event corresponding to the Promise-based asynchronous request in the memory through a custom commit grammar;
the calling module is used for calling the constructed asynchronous task manager to enable the asynchronous task manager to be packaged in a plurality of asynchronous tasks registered in the memory in a parallel mode;
and the transmission module is used for transmitting the ID and the serial number of the asynchronous event recorded in the source file to the asynchronous task manager, and executing the asynchronous request with the chain relation in the task manager in a parallel mode.
In a third aspect, an embodiment of the present invention further provides an electronic device, where the electronic device includes:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of processing a Promise-based chained asynchronous request in any of the preceding aspects or any implementation manner of the first aspect.
In a fourth aspect, an embodiment of the present invention further provides a non-transitory computer-readable storage medium storing computer instructions for causing a computer to execute the method for processing a Promise-based chained asynchronous request in the first aspect or any implementation manner of the first aspect.
In a fifth aspect, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, where the computer program includes program instructions, which, when executed by a computer, cause the computer to execute the method for processing a Promise-based chained asynchronous request in the first aspect or any implementation manner of the first aspect.
The chain type asynchronous request processing scheme based on the Promise in the embodiment of the invention comprises the steps of acquiring all asynchronous requests based on the Promise; registering an asynchronous event corresponding to the Promise-based asynchronous request in a memory through a custom commit grammar; calling the constructed asynchronous task manager to enable the asynchronous task manager to be packaged in a plurality of asynchronous tasks registered in a memory in a parallel mode; and transmitting the ID and the sequence number of the asynchronous event recorded in the source file to the asynchronous task manager, and executing the asynchronous request with the chain relation in the task manager in a parallel mode. By the processing scheme, the structure of the asynchronous task execution code is clearer, the dependency between asynchronous tasks is clearer, extra code does not need to be added for each asynchronous task, and the fact that the Promise encapsulation is manually added is not needed, so that the asynchronous task migration cost is lower, and execution and maintenance are more convenient.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic diagram of a chained asynchronous request processing flow based on Promise according to an embodiment of the present invention;
fig. 2 is a schematic diagram of another chain asynchronous request processing flow based on Promise according to an embodiment of the present invention;
fig. 3 is a schematic diagram of another chain asynchronous request processing flow based on Promise according to an embodiment of the present invention;
fig. 4 is a schematic diagram of another chain asynchronous request processing flow based on Promise according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a chain asynchronous request processing apparatus based on Promise according to an embodiment of the present invention;
fig. 6 is a schematic diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
Embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
The embodiments of the present disclosure are described below with specific examples, and other advantages and effects of the present disclosure will be readily apparent to those skilled in the art from the disclosure in the specification. It is to be understood that the described embodiments are merely illustrative of some, and not restrictive, of the embodiments of the disclosure. The disclosure may be embodied or carried out in various other specific embodiments, and various modifications and changes may be made in the details within the description without departing from the spirit of the disclosure. It is to be noted that the features in the following embodiments and examples may be combined with each other without conflict. All other embodiments, which can be derived by a person skilled in the art from the embodiments disclosed herein without making any creative effort, shall fall within the protection scope of the present disclosure.
It is noted that various aspects of the embodiments are described below within the scope of the appended claims. It should be apparent that the aspects described herein may be embodied in a wide variety of forms and that any specific structure and/or function described herein is merely illustrative. Based on the disclosure, one skilled in the art should appreciate that one aspect described herein may be implemented independently of any other aspects and that two or more of these aspects may be combined in various ways. For example, an apparatus may be implemented and/or a method practiced using any number of the aspects set forth herein. Additionally, such an apparatus may be implemented and/or such a method may be practiced using other structure and/or functionality in addition to one or more of the aspects set forth herein.
It should be noted that the drawings provided in the following embodiments are only for illustrating the basic idea of the present disclosure, and the drawings only show the components related to the present disclosure rather than the number, shape and size of the components in actual implementation, and the type, amount and ratio of the components in actual implementation may be changed arbitrarily, and the layout of the components may be more complicated.
In addition, in the following description, specific details are provided to facilitate a thorough understanding of the examples. However, it will be understood by those skilled in the art that the aspects may be practiced without these specific details.
The embodiment of the disclosure provides a chain type asynchronous request processing method based on Promise. The Promise-based chained asynchronous request processing method provided by the embodiment may be executed by a computing device, which may be implemented as software or as a combination of software and hardware, and may be integrally provided in a server, a terminal device, or the like.
Referring to fig. 1, a chain asynchronous request processing method based on Promise provided by the embodiment of the present invention includes the following steps:
s101, acquiring all the Promise-based asynchronous requests.
The calling objects with various dependency relationships exist in the same page, asynchronous programming can be abstracted through Promise, and a returned value or a thrown exception of a function needing asynchronous processing can be represented by adopting the Promise as a proxy object. The Promise object can represent an asynchronous operation, and the asynchronous object and the callback function can be separated.
Taking a web page containing a JavaScript language as an example, for a web page, the web page usually contains more display contents (for example, characters, pictures, tables, and the like), in order to obtain an asynchronous request on a current page, all the display contents on the current page may be obtained first, different contents correspond to different source addresses, and whether there are multiple content sources for the display contents may be determined based on the contents on the page.
When the display content is from multiple content sources, a Promise-based asynchronous request may be determined based on the multiple content sources. Specifically, a plurality of content requests corresponding to the plurality of content sources may be searched, and by determining whether a dependency relationship exists between the plurality of content requests, if a dependency relationship exists between the plurality of content requests, a content request based on a chained asynchronous request relationship is selected from the plurality of content requests as a Promise-based asynchronous request.
And S102, registering the asynchronous event corresponding to the Promise-based asynchronous request in the memory through the customized commit grammar.
The traditional Promise-based asynchronous call still has the problem of deeper code call level. To this end, a custom commit grammar is utilized to solve this problem. The commit function is defined through commit syntax, the commit function can receive character string parameters related to asynchronous call relations, after the character string parameters are received, tasks matched with the character strings are selected in an addressing memory of the current equipment through a character string matching mode based on the same naming method, and whether the tasks are asynchronous tasks is further judged.
If the task is not an asynchronous task, the result is directly called and returned. If the task is an asynchronous task and there is no asynchronous task currently in call, the current task is executed.
And when the execution of an asynchronous task is finished, continuously searching whether a temporary and un-called task set exists in the memory, if so, calling and repeatedly executing the process of judging whether the task is the asynchronous task. If the task currently being called exists, storing the task into an asynchronous task calling set, and calling after the task currently being executed is finished. And when all the asynchronous tasks are called, judging whether global error processing and successful processing exist or not when the current calling is finished, if so, returning the result to the corresponding processing, and if not, directly returning the result.
S103, calling the constructed asynchronous task manager to enable the asynchronous task manager to be packaged in a plurality of asynchronous tasks registered in the memory in a parallel mode.
In order to make the asynchronous tasks corresponding to the Promise more standard, an asynchronous task manager is set, and the asynchronous tasks are managed through the asynchronous task manager, so that the calling relation among the asynchronous tasks can be more parallelized.
Specifically, firstly, the asynchronous tasks needed to be used are registered in advance in the memory, and the asynchronous tasks are encapsulated through a self-defined asynchronous task server framework, so that the tasks in the execution process can be ensured to conform to a basic format in the framework, namely a format conforming to the Promise asynchronous specification, and the tasks themselves are successfully registered when the framework is initialized. In the process of calling the asynchronous task, receiving the conditions of calling the name, sequence, state, concurrence and the like of the asynchronous task by an instruction, executing the task as required in a frame, and dynamically deciding whether to execute the next task or return a result according to the current execution state.
S104, transmitting the ID and the sequence number of the asynchronous event recorded in the source file to the asynchronous task manager, and executing the asynchronous request with the chain relation in the task manager in a parallel mode.
After the completion of the setup of the asynchronous task manager, calls to the asynchronous task may be received and managed by the asynchronous task manager. Specifically, the ID and the sequence number of the asynchronous event may be transmitted to the asynchronous task manager, and the asynchronous task manager may execute the asynchronous request having a chain relationship in parallel through the ID and the sequence number of the asynchronous event. Therefore, the problem that callback hierarchy deepens in task execution due to the fact that deeper calling relation exists between asynchronous tasks is solved.
Referring to fig. 2, according to a specific implementation manner of the embodiment of the present invention, the step S101 of acquiring all the Promise-based asynchronous requests may include the following steps:
s201, display content on the current page is obtained.
Taking a web page containing a JavaScript language as an example, for a web page, the web page usually contains more display contents (e.g., text, pictures, tables, etc.), and in order to obtain an asynchronous request on a current page, all the display contents on the current page may be obtained first.
S202, judging whether the display content has a plurality of content sources.
Different contents correspond to different source addresses, and whether the display contents have a plurality of content sources can be judged based on the source addresses of the contents on the page.
S203, if yes, determining a Promise-based asynchronous request based on a plurality of content sources.
In the implementation process of step S203, the method may specifically include:
s2031, searching a plurality of content requests corresponding to the plurality of content sources;
s2032, selecting a content request based on the content request having the chained asynchronous request relationship from the plurality of content requests as a Promise-based asynchronous request.
When the display content is from multiple content sources, a Promise-based asynchronous request may be determined based on the multiple content sources. Specifically, a plurality of content requests corresponding to the plurality of content sources may be searched, and by determining whether a dependency relationship exists between the plurality of content requests, if a dependency relationship exists between the plurality of content requests, a content request based on a chained asynchronous request relationship is selected from the plurality of content requests as a Promise-based asynchronous request.
Referring to fig. 3, according to a specific implementation manner of the embodiment of the present invention, the step S102 of registering, in the memory, the asynchronous event corresponding to the Promise-based asynchronous request through the custom commit syntax may include the following steps:
s301, receiving a character string parameter by setting a commit function.
The traditional Promise-based asynchronous call still has the problem of deeper code call level. To this end, a custom commit grammar is utilized to solve this problem. The commit function is defined by a commit syntax and is capable of receiving string parameters related to asynchronous call relationships.
S302, searching the running task with the same parameter as the character string in the addressing memory in a character string matching mode.
After receiving the character string parameters, selecting a task matched with the character string in an addressing memory of the current equipment in a character string matching mode based on the same naming method, and further judging whether the task is an asynchronous task.
S303, selecting an asynchronous task meeting the conditions from the running tasks with the same character string parameters to register.
If the task is not an asynchronous task, the result is directly called and returned. If the task is an asynchronous task and there is no asynchronous task currently in call, the current task is executed.
And when the execution of an asynchronous task is finished, continuously searching whether a temporary and un-called task set exists in the memory, if so, calling and repeatedly executing the process of judging whether the task is the asynchronous task. If the task currently being called exists, storing the task into an asynchronous task calling set, and calling after the task currently being executed is finished. And when all the asynchronous tasks are called, judging whether global error processing and successful processing exist or not when the current calling is finished, if so, returning the result to the corresponding processing, and if not, directly returning the result.
Referring to fig. 4, according to a specific implementation manner of the embodiment of the present invention, step S103 constructs an asynchronous task manager, so that the asynchronous task manager encapsulates multiple asynchronous tasks registered in a memory in a parallel manner, including:
s401, the asynchronous tasks required to be used are registered in advance in the memory.
Specifically, the object corresponding to the asynchronous task may be set as an object in a key-value format, a data structure of linked list hashes is constructed, the data structure includes an array and a linked list, and the object of the asynchronous task is stored in the memory through the data structure.
S402, the asynchronous task is packaged through the framework, and the task in the execution process is ensured to conform to the format of the Promise asynchronous specification in the framework.
And encapsulating functions and classes related to asynchronous tasks through the framework, and only providing one interface for the outside. After the asynchronous tasks are encapsulated according to the Promise asynchronous specification, when different asynchronous tasks need to be called, only parameters related to the asynchronous tasks need to be called.
And S403, completing registration when the asynchronous task is initialized in the framework.
Besides the processing steps S401 to S403, according to a specific implementation manner of the embodiment of the present invention, the constructing an asynchronous task manager to enable the asynchronous task manager to encapsulate a plurality of asynchronous tasks registered in a memory in a parallel manner may further include: receiving the name, sequence, state and concurrency information of calling asynchronous tasks in the calling process of the asynchronous task manager; the decision of the dynamic according to the current execution state is to execute the next task or return the result.
Corresponding to the above method embodiment, referring to fig. 5, the embodiment of the present invention further discloses a chained asynchronous request processing apparatus 50 based on Promise, including:
an obtaining module 501, configured to obtain all the Promise-based asynchronous requests.
The calling objects with various dependency relationships exist in the same page, asynchronous programming can be abstracted through Promise, and a returned value or a thrown exception of a function needing asynchronous processing can be represented by adopting the Promise as a proxy object. The Promise object can represent an asynchronous operation, and the asynchronous object and the callback function can be separated.
Taking a web page containing a JavaScript language as an example, for a web page, the web page usually contains more display contents (for example, characters, pictures, tables, and the like), in order to obtain an asynchronous request on a current page, all the display contents on the current page may be obtained first, different contents correspond to different source addresses, and whether there are multiple content sources for the display contents may be determined based on the contents on the page.
When the display content is from multiple content sources, a Promise-based asynchronous request may be determined based on the multiple content sources. Specifically, a plurality of content requests corresponding to the plurality of content sources may be searched, and by determining whether a dependency relationship exists between the plurality of content requests, if a dependency relationship exists between the plurality of content requests, a content request based on a chained asynchronous request relationship is selected from the plurality of content requests as a Promise-based asynchronous request.
A registering module 502, configured to register, in the memory, an asynchronous event corresponding to the Promise-based asynchronous request through a custom commit syntax.
The traditional Promise-based asynchronous call still has the problem of deeper code call level. To this end, a custom commit grammar is utilized to solve this problem. A commit function is defined through commit syntax, the commit function can receive character string parameters related to asynchronous call relation, after receiving the character string parameters, a task matched with the character string is selected in an addressing memory of the current equipment based on a same naming method through a character string matching mode, and whether the task is an asynchronous task is further judged.
If the task is not an asynchronous task, the result is directly called and returned. If the task is an asynchronous task and there is no asynchronous task currently in call, the current task is executed.
And when the execution of an asynchronous task is finished, continuously searching whether a temporary and un-called task set exists in the memory, if so, calling and repeatedly executing the process of judging whether the task is the asynchronous task. If the task currently being called exists, storing the task into an asynchronous task calling set, and calling after the task currently being executed is finished. And when all the asynchronous tasks are called, judging whether global error processing and successful processing exist or not when the current calling is finished, if so, returning the result to the corresponding processing, and if not, directly returning the result.
The invoking module 503 is configured to invoke the constructed asynchronous task manager, so that the asynchronous task manager is packaged in parallel in a plurality of asynchronous tasks registered in the memory.
In order to make the asynchronous tasks corresponding to the Promise more standard, an asynchronous task manager is set, and the asynchronous tasks are managed through the asynchronous task manager, so that the calling relation among the asynchronous tasks can be more parallelized.
Specifically, firstly, the asynchronous tasks needed to be used are registered in advance in the memory, and the asynchronous tasks are encapsulated through a self-defined asynchronous task server framework, so that the tasks in the execution process can be ensured to conform to a basic format in the framework, namely a format conforming to the Promise asynchronous specification, and the tasks themselves are successfully registered when the framework is initialized. In the process of calling the asynchronous task, receiving the conditions of calling the name, sequence, state, concurrence and the like of the asynchronous task by an instruction, executing the task as required in a frame, and dynamically deciding whether to execute the next task or return a result according to the current execution state.
A transferring module 504, configured to transfer the ID and the sequence number of the asynchronous event recorded in the source file to the asynchronous task manager, where the task manager executes an asynchronous request with a chain relation in a parallel manner.
After the completion of the setup of the asynchronous task manager, calls to the asynchronous task may be received and managed by the asynchronous task manager. Specifically, the ID and the sequence number of the asynchronous event may be transmitted to the asynchronous task manager, and the asynchronous task manager may execute the asynchronous request having a chain relationship in parallel through the ID and the sequence number of the asynchronous event. Therefore, the problem that callback hierarchy deepens in task execution due to the fact that deeper calling relation exists between asynchronous tasks is solved.
The apparatus shown in fig. 5 may correspondingly execute the content in the above method embodiment, and details of the part not described in detail in this embodiment refer to the content described in the above method embodiment, which is not described again here.
Referring to fig. 6, an embodiment of the present invention further provides an electronic device 60, where the electronic device includes:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method for processing a Promise-based chained asynchronous request in the above method embodiments.
Embodiments of the present invention also provide a non-transitory computer-readable storage medium storing computer instructions for causing a computer to perform the foregoing method embodiments.
Embodiments of the present invention also provide a computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions that, when executed by a computer, cause the computer to perform the method of premise-based chained asynchronous request processing in the aforementioned method embodiments.
Referring now to FIG. 6, a block diagram of an electronic device 60 suitable for use in implementing embodiments of the present disclosure is shown. The electronic devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., car navigation terminals), and the like, and fixed terminals such as digital TVs, desktop computers, and the like. The electronic device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 6, the electronic device 60 may include a processing means (e.g., a central processing unit, a graphics processor, etc.) 601 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage means 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the electronic apparatus 60 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
Generally, the following devices may be connected to the I/O interface 605: input devices 606 including, for example, a touch screen, touch pad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; output devices 607 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 608 including, for example, tape, hard disk, etc.; and a communication device 609. The communication means 609 may allow the electronic device 60 to communicate with other devices wirelessly or by wire to exchange data. While the figures illustrate an electronic device 60 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 609, or may be installed from the storage means 608, or may be installed from the ROM 602. The computer program, when executed by the processing device 601, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: acquiring at least two internet protocol addresses; sending a node evaluation request comprising the at least two internet protocol addresses to node evaluation equipment, wherein the node evaluation equipment selects the internet protocol addresses from the at least two internet protocol addresses and returns the internet protocol addresses; receiving an internet protocol address returned by the node evaluation equipment; wherein the obtained internet protocol address indicates an edge node in the content distribution network.
Alternatively, the computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: receiving a node evaluation request comprising at least two internet protocol addresses; selecting an internet protocol address from the at least two internet protocol addresses; returning the selected internet protocol address; wherein the received internet protocol address indicates an edge node in the content distribution network.
Computer program code for carrying out operations for aspects of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of a unit does not in some cases constitute a limitation of the unit itself, for example, the first retrieving unit may also be described as a "unit for retrieving at least two internet protocol addresses".
It should be understood that portions of the present invention may be implemented in hardware, software, firmware, or a combination thereof.
The above description is only for the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (11)

1. A chain asynchronous request processing method based on Promise is characterized by comprising the following steps:
acquiring all Promise-based asynchronous requests;
registering the asynchronous event corresponding to the Promise-based asynchronous request in a memory through a custom commit grammar, wherein the registering comprises the following steps: receiving a character string parameter by setting a commit function; searching a running task with the same parameters as the character strings in an addressing memory in a character string matching mode; selecting an asynchronous task meeting the conditions from the running tasks with the same character string parameters for registration;
calling the constructed asynchronous task manager to enable the asynchronous task manager to be packaged in a plurality of asynchronous tasks registered in a memory in a parallel mode;
and transmitting the ID and the sequence number of the asynchronous event recorded in the source file to the asynchronous task manager, and executing the asynchronous request with the chain relation in the task manager in a parallel mode.
2. The method of claim 1, wherein obtaining all Promise-based asynchronous requests comprises:
acquiring display content on a current page;
judging whether the display content has a plurality of content sources;
if so, a Promise-based asynchronous request is determined based on the plurality of content sources.
3. The method of claim 2, wherein determining the Promise-based asynchronous request based on the plurality of content sources comprises:
searching a plurality of content requests corresponding to the plurality of content sources;
a content request based on a content having a chained asynchronous request relationship is selected from the plurality of content requests as a Promise-based asynchronous request.
4. The method of claim 1, wherein the selecting an asynchronous task meeting the condition from the running tasks with the same character string parameter for registration comprises:
judging whether the running task with the same character string parameter is an asynchronous task or not;
if so, executing the current task under the condition that the called asynchronous task does not exist at present, and searching whether a task set which is temporarily stored and is not called exists in a memory or not after the execution is finished;
if the temporary and un-called task set is stored in the memory after the execution is finished, the current process is called and repeated, if the task currently being called exists, the un-called task set is stored in the asynchronous task calling set, and the calling is carried out after the current execution task is finished.
5. The method according to claim 4, wherein the selecting an asynchronous task meeting the condition from the running tasks with the same character string parameter for registration further comprises:
when all the asynchronous tasks are called, further judging whether global error processing and successful processing exist when the current calling is finished;
if the result exists, the result is returned to the corresponding processing, otherwise, the processing result is directly returned.
6. The method of claim 1, wherein invoking the constructed asynchronous task manager causes the asynchronous task manager to encapsulate a plurality of asynchronous tasks registered in a memory in a parallel manner, comprising:
registering the asynchronous tasks required to be used in the memory in advance;
encapsulating the asynchronous task through a frame to ensure that the task in the execution process conforms to the format of the Promise asynchronous specification in the frame;
and completing registration when the asynchronous task is initialized in the framework.
7. The method of claim 5, wherein invoking the constructed asynchronous task manager causes the asynchronous task manager to encapsulate a plurality of asynchronous tasks registered in a memory in a parallel manner, further comprising:
receiving the name, sequence, state and concurrency information of calling asynchronous tasks in the calling process of the asynchronous task manager;
the decision of the dynamic according to the current execution state is to execute the next task or return the result.
8. The method of claim 1, wherein executing asynchronous requests having a chained relationship in parallel in the task manager comprises:
synchronously registering all asynchronous events to be executed through commit grammar;
and setting an asynchronous event executor used for executing each asynchronous event inside the framework of the task manager, wherein the asynchronous event executor executes the callback of the Promise according to the state of the asynchronous event.
9. A Promise-based chained asynchronous request processing apparatus, comprising:
the acquisition module is used for acquiring all the Promise-based asynchronous requests;
the registration module is used for registering the asynchronous event corresponding to the Promise-based asynchronous request in the memory through a customized commit grammar: receiving a character string parameter by setting a commit function; searching a running task with the same parameters as the character strings in an addressing memory in a character string matching mode; selecting an asynchronous task meeting the conditions from the running tasks with the same character string parameters for registration;
the calling module is used for calling the constructed asynchronous task manager to enable the asynchronous task manager to be packaged in a plurality of asynchronous tasks registered in the memory in a parallel mode;
and the transmission module is used for transmitting the ID and the serial number of the asynchronous event recorded in the source file to the asynchronous task manager, and executing the asynchronous request with the chain relation in the task manager in a parallel mode.
10. An electronic device, characterized in that the electronic device comprises:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the Promise-based chained asynchronous request processing method of any of the preceding claims 1-8.
11. A non-transitory computer-readable storage medium storing computer instructions for causing a computer to perform the Promise-based chained asynchronous request processing method of any of the preceding claims 1-8.
CN201811394545.XA 2018-11-22 2018-11-22 Chain type asynchronous request processing method and device based on Promise and electronic equipment Active CN109669720B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811394545.XA CN109669720B (en) 2018-11-22 2018-11-22 Chain type asynchronous request processing method and device based on Promise and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811394545.XA CN109669720B (en) 2018-11-22 2018-11-22 Chain type asynchronous request processing method and device based on Promise and electronic equipment

Publications (2)

Publication Number Publication Date
CN109669720A CN109669720A (en) 2019-04-23
CN109669720B true CN109669720B (en) 2022-05-10

Family

ID=66141929

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811394545.XA Active CN109669720B (en) 2018-11-22 2018-11-22 Chain type asynchronous request processing method and device based on Promise and electronic equipment

Country Status (1)

Country Link
CN (1) CN109669720B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113094618A (en) * 2021-04-08 2021-07-09 中国工商银行股份有限公司 Method, apparatus, device and storage medium for performing asynchronous request response operation
CN115687224A (en) * 2022-09-09 2023-02-03 杭州海康机器人股份有限公司 Asynchronous processing flow generation method and device

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105389209A (en) * 2015-12-25 2016-03-09 中国建设银行股份有限公司 Asynchronous batch task processing method and system
CN106911784A (en) * 2017-03-02 2017-06-30 北京奇鱼时代科技有限公司 A kind of method and apparatus for performing asynchronous event

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9515901B2 (en) * 2013-10-18 2016-12-06 AppDynamics, Inc. Automatic asynchronous handoff identification

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105389209A (en) * 2015-12-25 2016-03-09 中国建设银行股份有限公司 Asynchronous batch task processing method and system
CN106911784A (en) * 2017-03-02 2017-06-30 北京奇鱼时代科技有限公司 A kind of method and apparatus for performing asynchronous event

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
使用Promise链式调用解决多个异步回调的问题;Superman;《https://m.jb51.net/article/103068.htm》;20170115;第1-3页 *

Also Published As

Publication number Publication date
CN109669720A (en) 2019-04-23

Similar Documents

Publication Publication Date Title
CN111338623B (en) Method, device, medium and electronic equipment for developing user interface
CN112286529A (en) Development method, device and equipment of front-end page and storage medium
CN111930534A (en) Data calling method and device and electronic equipment
CN111581555B (en) Document loading method, device, equipment and storage medium
CN111367516B (en) Application interface generation method and device and electronic equipment
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN111338944B (en) Remote Procedure Call (RPC) interface testing method, device, medium and equipment
CN109669720B (en) Chain type asynchronous request processing method and device based on Promise and electronic equipment
CN113761871A (en) Rich text rendering method and device, electronic equipment and storage medium
CN112558933B (en) Component rendering method and device, readable medium and electronic equipment
CN112650804B (en) Big data access method, device, system and storage medium
WO2024212839A1 (en) Card layout method and apparatus, medium and electronic device
CN113391860B (en) Service request processing method and device, electronic equipment and computer storage medium
CN111752644A (en) Interface simulation method, device, equipment and storage medium
CN113296771B (en) Page display method, device, equipment and computer readable medium
CN112818267A (en) Data processing method and device, computer readable storage medium and electronic equipment
CN116781586A (en) gRPC flow analysis method, device, equipment and medium
CN116860286A (en) Page dynamic update method, device, electronic equipment and computer readable medium
CN113779122B (en) Method and device for exporting data
CN112688863B (en) Gateway data processing method and device and electronic equipment
CN113835790A (en) Paging page display method and device based on Android
CN117112500B (en) Resource management method, device, equipment and storage medium
CN112445517B (en) Inlet file generation method, device, electronic equipment and computer readable medium
CN111240657A (en) Method and device for generating SDK and electronic equipment
CN113157365B (en) Program running method, program running device, electronic equipment and computer readable medium

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