Processing method and system for realizing asynchronous callback

By parsing and generating asynchronous callback call code or constructing closure objects using structured expression units, the problem of excessively deep nested callback functions is solved, improving code conciseness and readability, and reducing error rate and maintenance costs.

CN121900763APending Publication Date: 2026-04-21GUANGZHOU YUNBIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
GUANGZHOU YUNBIAO NETWORK TECH CO LTD
Filing Date
2025-11-25
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

Existing asynchronous programming mechanisms can easily lead to deeply nested callback functions in complex systems, creating a "callback hell" phenomenon that makes the code difficult to read and maintain, and prone to errors.

Method used

Using structured expression units, asynchronous callback call code or closure objects are parsed and generated by identifying declaration parts, target function declaration parts, callback parameter declaration parts, and callback function declaration parts, and then inserted into the parameter list of the target function call to realize the callback call.

Benefits of technology

It significantly reduces boilerplate code and glue code, avoids nested callbacks, improves code simplicity and readability, reduces error rate and maintenance costs, and enhances development efficiency and execution consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121900763A_ABST
    Figure CN121900763A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computer software, in particular to a processing method for realizing asynchronous callback, which is based on a structured expression unit, and realizes callback calling of at least one callback function in at least one objective function calling through the following steps: based on an identification declaration part, calling at least one objective function; identifying at least one structured expression unit in the source program, and further executing the following steps on any structured expression unit: analyzing the structured expression unit to obtain a target function declaration part, a callback parameter declaration part and a callback function declaration part; according to an analysis result, an asynchronous callback calling code is generated, a callback function in the asynchronous callback calling code is inserted into a parameter list called by the target function, and the asynchronous callback calling code is executed; or constructing a closure object of the callback function, inserting the closure object into the parameter list called by the target function, and calling the closure object to execute the callback function when the call of the target function meets the preset triggering condition.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer software technology, and in particular to a processing method and system for implementing asynchronous callbacks. Background Technology

[0002] In modern software development, asynchronous programming models are widely used in scenarios such as network communication, data processing, user interface interaction, and multi-threaded task management.

[0003] Existing asynchronous programming mechanisms typically employ callback functions. This involves passing a function as an argument when invoking an asynchronous operation, and then calling the callback function to return the result after the operation completes. However, as system complexity increases, dependencies often exist between asynchronous operations, requiring developers to nest callback functions within each other to control the order of operations. With numerous nesting levels, the code structure indents to the right, creating what's commonly known as "callback hell." This code structure not only makes program logic difficult to read and maintain but also increases the risk of errors in exception handling, scope management, and parameter passing. Summary of the Invention

[0004] In one example provided by this invention, a method for implementing asynchronous callbacks is proposed. When executed in a computer system, based on a structured expression unit, the method implements the callback invocation of at least one callback function in at least one target function call through the following steps, wherein the structured expression unit includes at least an identifier declaration section, a target function declaration section, a callback parameter declaration section, and a callback function declaration section:

[0005] Based on the aforementioned identifier declaration section, at least one structured expression unit in the source program is identified, and the following steps are further performed on any structured expression unit:

[0006] The structured representation unit is parsed to obtain the target function declaration, the callback parameter declaration, and the callback function declaration.

[0007] According to the analysis results,

[0008] Generate asynchronous callback call code, in which the callback function is inserted into the parameter list of the target function call, and execute the asynchronous callback call code to implement the callback call; or

[0009] A closure object for the callback function is constructed, and the closure object is inserted into the parameter list of the target function call. When the target function call meets a predetermined triggering condition, the closure object is called to execute the callback function, thereby realizing the callback call.

[0010] Based on the processing method for implementing asynchronous callbacks provided in the above examples, in one or more other examples provided by the present invention, the identifier declaration section includes a start identifier declaration section;

[0011] In the source program, each of the starting identifier declaration sections is used to uniquely identify the starting position of a corresponding structured expression unit.

[0012] Based on the processing method for implementing asynchronous callbacks provided in the above examples, in one or more other examples provided by the present invention, the step of identifying at least one structured expression unit in the source program based on the identifier declaration section includes the following steps:

[0013] Scan and locate all the start identifier declaration sections in the source program, and based on each start identifier declaration section:

[0014] Based on the context of the start identifier declaration section, determine its corresponding end identifier;

[0015] The expression boundary of the corresponding structured expression unit is determined based on the start identifier declaration part and its corresponding end identifier.

[0016] Based on the asynchronous callback processing method provided in the above examples, in one or more other examples provided by this invention, the end marker is determined according to the following rules, in the order of their appearance:

[0017] If, within the same statement block as the start identifier declaration, there are no executable statements or declarations affecting program semantics after the start identifier declaration and before the next start identifier declaration, then the first appearing next start identifier declaration is confirmed as the end identifier of the structured expression unit; otherwise...

[0018] The end marker is any of the following that appears first: the end marker of the statement block, the end marker of the host function, or the end marker of the source file.

[0019] Based on the asynchronous callback processing method provided in the above examples, in one or more other examples provided by this invention, the structured expression unit further includes:

[0020] The callback parameter positioning declaration section is used to indicate the insertion position of the callback function or the closure object in the parameter list of the target function call.

[0021] Based on the processing method for implementing asynchronous callbacks provided in the above examples, in one or more other examples provided by this invention, the callback parameter positioning declaration is represented in any structured expression unit as an ordinal number with a first symbol or a second symbol, wherein:

[0022] Ordinal numbers with a first sign represent the insertion position starting from the first position of the parameter list, while ordinal numbers with a second sign represent the insertion position starting from the last position of the parameter list.

[0023] Furthermore, the first symbol and the second symbol are different from each other in terms of glyph or code position, and can be uniquely distinguished at the lexical level.

[0024] Based on the processing method for implementing asynchronous callbacks provided in the above examples, in one or more other examples provided by the present invention, the callback parameter positioning declaration section indicates, without being shown, that the insertion position is a preset insertion position in any structured expression unit.

[0025] Based on the processing method for implementing asynchronous callbacks provided in the above examples, in one or more other examples provided by the present invention, the preset insertion position is the last position of the parameter list of the target function call.

[0026] Based on the asynchronous callback processing method provided in the above examples, in one or more other examples provided by the present invention, for any two consecutive structured expression units in any statement block in the source program, the callback calls of the two structured expression units are implemented one by one according to their writing order in the corresponding statement block.

[0027] Based on the processing method for implementing asynchronous callbacks provided in the above examples, the present invention also proposes a processing system for implementing asynchronous callbacks in one or more other examples, including: a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, it implements the processing method for implementing asynchronous callbacks proposed in any of the above examples. Attached Figure Description

[0028] From the following description of embodiments in conjunction with the accompanying drawings, aspects, features, and advantages of the present invention will become clearer and more readily understood, in which:

[0029] Figure 1 This illustrates a processing method flow for implementing asynchronous callbacks in an example provided by the present invention;

[0030] Figure 2 This example illustrates the system architecture used to implement asynchronous callbacks.

[0031] Figure 3 This illustrates the components of a structured representation unit in the processing method used to implement asynchronous callbacks, as described in this example.

[0032] Figure 4 This illustrates the identification process of at least one structured representation unit in the source program of an example provided by the present invention. Detailed Implementation

[0033] According to an embodiment of the present invention, a processing method embodiment for implementing asynchronous callback is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0034] Figure 1 This illustrates a processing method flow for implementing asynchronous callbacks in an example provided by the present invention; Figure 2 This example illustrates the system architecture used to implement asynchronous callbacks. Figure 3 This illustrates the components of a structured representation unit in the processing method used to implement asynchronous callbacks, as described in this example.

[0035] like Figure 3 As shown, the structured expression unit proposed in this example includes at least an identifier declaration section, an objective function declaration section, a callback parameter declaration section, and a callback function declaration section.

[0036] Furthermore, the identification declaration section is used to uniquely indicate and locate the start or end position of the structured expression unit, thereby triggering the parsing and boundary determination process of the structured expression unit.

[0037] In one embodiment provided by the present invention, the identifier declaration section includes a start identifier declaration section; further, in the source program, each of the start identifier declaration sections is used to uniquely identify the start position of a corresponding structured expression unit.

[0038] As provided in one specific embodiment of the present invention, a structured expression unit is provided, which is defined as a Pump statement block, the Pump statement block including at least one of the aforementioned start identifier declaration sections.

[0039] For example, in a specific Pump statement block, it can be expressed as "Let => s:Fetch(url), <response>In "+1", the starting identifier declaration part is: "Let =>".

[0040] In yet another specific Pump statement block, "Let => a:response.Json(), <json>In this context, the starting identifier declaration section is similarly represented as "Let =>".

[0041] In another specific Pump statement block, "Let => response.Json(), <json>In this context, the starting identifier declaration section is still represented as "Let =>".

[0042] In any of the above embodiments, the Pump statement block is identified and located by lexical / syntactic analysis based on "Let =>" during the compilation stage or the preprocessing stage before interpreted execution.

[0043] It should be noted that, in some other specific embodiments, the starting identifier declaration of the structured expression unit (such as the Pump statement block in the above embodiments) described in any example of the present invention can also be any keyword, symbol sequence or annotation mark that can be uniquely identified and located by lexical / syntactic analysis rules and does not conflict with the existing syntax of the host language.

[0044] Furthermore, the target function declaration section is used to indicate the target function call, so as to determine the target function call expression and its parameter list, and thus serve as the basis for calculating the subsequent callback insertion position and determining the triggering condition.

[0045] The Pump statement block provided in the above embodiment also includes a target function declaration section.

[0046] Furthermore, based on a specific expression of the above Pump statement block, "Let => s:Fetch(url), <response>+1”, the objective function declaration part is represented as "s:Fetch(url)".

[0047] Based on another specific expression of the above Pump statement block, "Let => a:response.Json(), <json>The objective function declaration is represented as "a:response.Json()".

[0048] Based on another specific expression of the above Pump statement block, "Let => response.Json(), <json>The target function declaration is "response.Json()".

[0049] When the computer executes any of the above Pump statement blocks, it parses the receiver of the target function (such as s, a:response or response), the function name (such as Fetch, Json), and the parameter list (such as (url) or ()) based on the target function declaration part (such as s:Fetch(url), a:response.Json(), response.Json()) in the Pump statement block.

[0050] It should be noted that the objective function declaration section is only used to describe the call and does not trigger the evaluation or execution of the call during the resolution phase.

[0051] It should also be noted that the target function declaration is not limited to the specific form mentioned above. It can be any calling expression that can uniquely identify the called entity and its existing parameter list within the host language expression. Furthermore, any function that is compatible with the host language syntax and can be uniquely parsed by lexical / syntactic rules can be regarded as the target calling unit of the present invention.

[0052] Furthermore, the callback parameter declaration section is used to declare the formal parameter list of the callback function and its constraint information, and to establish an injection mapping relationship between the target function call output and the callback function formal parameters during code generation or runtime injection.

[0053] It should be noted that the callback parameter declaration section does not trigger any evaluation or execution; its function is only to declare and constrain the signature and parameter binding rules of the callback function.

[0054] As shown in the above embodiment, the Pump statement block further includes a callback parameter declaration section.

[0055] Furthermore, based on a specific expression of the above Pump statement block, "Let => s:Fetch(url), <response>+1", the callback parameter declaration is represented as " <response>The `"` directive is used to declare that the callback function receives a formal parameter named `response` when it is triggered, and to construct the callback function signature `__cb(response)` during the code generation phase, and to inject the return value from `s:Fetch(url)` into this formal parameter according to a predetermined mapping.

[0056] Based on another specific expression of the above Pump statement block, "Let => a:response.Json(), <json>The callback parameter declaration section is represented as "". <json>The `""` directive is used to declare a single formal parameter `json` and inject the return value from `response.Json()` into that formal parameter.

[0057] Based on another specific expression of the above Pump statement block, "Let => response.Json(), <>", the callback parameter declaration part is represented as "<>", which indicates an empty parameter list and is used to declare that the callback function body does not receive any parameters when triggered.

[0058] It should be noted that the callback parameter declaration section is only used to declare and constrain the formal parameters of the callback, and does not trigger the evaluation of the target function or any external expression during the parsing phase; it is not responsible for capturing external free variables (the capture of external variables is handled by the callback function body / closure mechanism).

[0059] It should also be noted that the callback parameter declaration section is not limited to the specific form mentioned above. It can be any parameter list expression that is compatible with the host language syntax and can be uniquely parsed by lexical / syntactic rules. Furthermore, any representation that can clearly correspond to the formal parameter table of the callback function and is used to establish the injection mapping can be regarded as the callback parameter declaration section of the present invention.

[0060] Furthermore, to eliminate ambiguity in formal parameter insertion and ensure the accuracy of callback injection, in some specific embodiments, the structured expression unit described in any of the above examples also includes a callback parameter positioning declaration section.

[0061] In these specific embodiments, the callback parameter positioning declaration section is used to indicate the specific insertion position of inserting the callback function or its callback closure as an actual parameter into the parameter list of the target function call; it should be noted that the callback parameter positioning declaration section does not trigger the evaluation of the target function or its actual parameter, and its function is only for position declaration and constraint.

[0062] Furthermore, in some embodiments, the callback parameter positioning declaration is represented in any structured expression unit as an ordinal number having a first symbol or a second symbol, and the first symbol and the second symbol are distinct from each other in terms of glyph or code position, and can be uniquely distinguished at the lexical level, wherein:

[0063] An ordinal number with the first sign represents the insertion position counting from the first position of the parameter list, such as being denoted as "+k", where k is a positive integer; in this case, a specific Pump statement block "Let => s:Fetch(url), <response>"+1" is based on the callback parameter to locate the declaration part "+1", which is equivalent to the following call expression "s.Fetch(__cb_response, url)".

[0064] An ordinal number with a second sign indicates the insertion position counting from the end of the parameter list, such as being denoted as "-k", where k is a positive integer; in this case, a specific Pump statement block "Let => s:Fetch(url), <response>-1" locates the declaration part based on the callback parameter"+1", which is equivalent to the following call expression "s.Fetch(url,__cb_response)".

[0065] Furthermore, in this or other embodiments, the callback parameter positioning declaration section, in any structured expression unit, indicates that the insertion position is a preset insertion position by not showing it. Usually, the preset insertion position is the last position of the parameter list, but in other implementations it can also be configured to other specific insertion positions.

[0066] As specifically stated in the Pump statement block above, "Let => a:response.Json(), <json>If the callback parameter positioning declaration is not shown, the equivalent call is "a:response.Json(__cb_json)" according to the default rule (last character).

[0067] Furthermore, the callback function declaration section is used to carry and limit the set of execution statements when the callback is triggered, and to define the start and end boundaries of the set of statements so that it can be encapsulated as the function body of the callback function during the code generation or runtime injection phase, and to construct a callback closure in the runtime environment to carry its definition environment when it is necessary to capture external free variables.

[0068] In one embodiment provided by the present invention, the starting position of the callback function body declaration section is the first valid statement after the declaration line of the corresponding structured expression unit (such as the Pump statement block), and its ending position is the end marker determined according to the boundary rules.

[0069] Furthermore, the end identifier is determined according to the following rules, based on the order of appearance: if there are no executable statements or declarations affecting program semantics within the same statement block as the start identifier declaration, and there is no such statement after the start identifier declaration and before the next start identifier declaration, then the next start identifier declaration that appears first is confirmed as the end identifier of the structured expression unit; otherwise, the end identifier is any of the following that appears first: the end marker of the statement block, the end marker of the host function, or the end marker of the source file.

[0070] In a specific Pump statement block:

[0071] Let => response.Json(), <json>

[0072] echo string(json)

[0073] The callback function declaration in this Pump block is a set of consecutive statements starting from "echo string(json)" and ending at the position determined by the aforementioned boundary rules.

[0074] In yet another specific Pump statement block:

[0075] Let => s:Fetch(url), <response>+1

[0076] Let => a:response.Json(), <json>

[0077] echo string(json)

[0078] This Pump statement block includes: the first callback function body declaration section, which is an empty body, i.e., it is truncated by the second start marker declaration section; the first callback function body declaration section is a set of statements from "echo string(json)" to the end of the block.

[0079] It should be noted that the specific representation of the callback function body declaration is not limited to a specific syntax form. Any function that is compatible with the host language syntax, can be uniquely resolved into a continuous statement range by lexical / syntactic rules, and can be clearly mapped to a callback function body during the code generation stage can be regarded as the callback function body declaration of this invention.

[0080] The structured expression unit provided in this embodiment changes the asynchronous callback from handwritten nesting to near-linear declarative writing, which can significantly reduce boilerplate and glue code and avoid nested callbacks. Furthermore, the structured expression unit can be translated at compile time or injected at runtime by explicitly annotating the target call, callback parameters and insertion position, without changing the existing evaluation order and side effect timing, thereby improving code conciseness and readability, reducing error rate and maintenance cost, and helping to significantly improve development efficiency and execution consistency.

[0081] like Figure 1 As shown, the asynchronous callback handling method used in this example is based on, for example... Figure 3 The structured representation unit shown implements the callback invocation of at least one callback function in at least one target function call through the following steps:

[0082] S01. Based on the identification declaration section, identify at least one structured expression unit in the source program, and further perform the following steps on any structured expression unit:

[0083] S02. Parse the structured expression unit to obtain the target function declaration part, the callback parameter declaration part, and the callback function declaration part;

[0084] S03. Based on the analysis results

[0085] S031a. Generate asynchronous callback call code, wherein the callback function in the asynchronous callback call code is inserted into the parameter list of the target function call, and the callback call is implemented by executing the asynchronous callback call code; or

[0086] S031b constructs a closure object for the callback function, inserts the closure object into the parameter list of the target function call, and calls the closure object to execute the callback function when the target function call meets a predetermined triggering condition, thereby realizing the callback call.

[0087] Furthermore, in the process of parsing multiple structured representation units contained in the source program, to avoid the boundary determination of the previous structured representation unit affecting the boundary determination of the next structured representation unit, that is, to ensure the determinism of semantic segmentation, in this example, step S01, based on the identifier declaration section, identifies at least one structured representation unit in the source program, and through methods such as... Figure 4 The process shown is implemented as follows:

[0088] S011. Scan and locate all the start identifier declaration sections in the source program, and based on each start identifier declaration section:

[0089] S012. Determine an end identifier corresponding to the start identifier declaration section based on its context;

[0090] S013. Determine the expression boundary of the corresponding structured expression unit based on the start identifier declaration part and its corresponding end identifier.

[0091] In this example, steps S011 to S013 constitute a boundary determination process for one-time full recognition, thereby avoiding boundary crosstalk between preceding and following units, ensuring the determinism of semantic segmentation, and providing stable anchor points for subsequent semantic parsing, position calculation, and code generation / runtime injection.

[0092] Furthermore, to ensure the determinism of the dependencies and triggering order of consecutive structured expression units, in this example, for any two consecutive structured expression units within any statement block in the source program, the callback calls of the two structured expression units are executed one by one according to their writing order within the corresponding statement block.

[0093] Specifically, within the same statement block, if the starting identifier declaration of the latter structured expression unit appears after the former structured expression unit, and there are no executable statements or declarations that affect semantics between the two (except for whitespace, newlines, comments, and compiler directives that do not produce execution semantics), then they are determined to be two consecutive structured expression units.

[0094] Two consecutive structured expression units are ordered based on their order in the source code: the target function call of the previous structured expression unit satisfies the predetermined triggering condition and completes its callback execution as the trigger point, and then the callback call of the next structured expression unit is implemented; if the callback function body declaration of the previous structured expression unit is empty, it still exists as a trigger node in the sequence chain and does not affect the subsequent sequential triggering; the callback insertion position of each structured expression unit is independently determined by its own callback parameter positioning declaration and does not affect each other.

[0095] Furthermore, when the processing method for implementing asynchronous callbacks implements the callback call based on steps S01, S02, S03, and S031a, the existing type checking, semantic analysis, and optimization links are reused by translating the structured expression unit into asynchronous callback call code compatible with the host language; and the callback is injected as an additional argument at a predetermined insertion position without changing the evaluation order of the original actual parameters of the target function call.

[0096] Furthermore, when this processing method for implementing asynchronous callbacks implements the callback call based on steps S01, S02, S03, and S031b, by directly constructing a closure object carrying the callback function at runtime based on the parsing result, and injecting the closure object into the predetermined insertion position of the parameter list of the target function call, the evaluation model and scheduling semantics consistent with the host language execution environment can be maintained without materializing or storing intermediate code.

[0097] Based on the asynchronous callback processing method proposed in the above example, in an application scenario where the host language is OSE, step S031a is selected to implement the callback call:

[0098] During the compilation phase, the system translates the identified and parsed structured representation units into OSE-compatible equivalent asynchronous call forms:

[0099] Based on the callback parameters, locate the declaration section or the preset insertion position, and inject the callback as an additional argument into the parameter list of the target function call, while maintaining the evaluation order of the existing arguments and the timing of side effects.

[0100] During the generation process, the type checking, semantic analysis and optimization links of OSE are reused, static verification and boundary checks are performed on the signature and insertion position, and in case of incompatibility or out-of-bounds situations, a localizable compile-time diagnosis is given or a rollback is performed according to the strategy.

[0101] For consecutive structured expression units within the same statement block, they are expanded into nested or equivalent serial trigger structures according to the order in which the source code is written, ensuring the determinism of the triggering order and data dependencies.

[0102] In this embodiment, the system uses the structured expression units identified in the source program as the basic units: for consecutive structured expression units within the same statement block, they are automatically converted into nested or equivalent serial trigger chains executed in the order of the source code, ensuring the determinism of the trigger order and data dependencies; at the same time, in the callback injection process corresponding to each structured expression unit, the evaluation order of the original actual parameters of its target function call and the timing of side effects are not changed, thereby maintaining semantic and performance consistency, and facilitating incremental construction and unified debugging in a large-scale codebase.

[0103] Furthermore, in OSE application scenarios, any structured expression unit in the source program can be directly embedded into the source program, participating in compilation and execution as a local declaration and code body component of its function (or module); or

[0104] First, embed the Neta statement block, then incorporate the Neta statement block as a whole into the source program as a host control domain, and implement sequential triggering and lifecycle management of the asynchronous steps within the block according to its event loop / scheduling semantics.

[0105] It should be noted that the two usage forms are equivalent in syntax and semantics, and the difference lies only in the host context and scheduling method.

[0106] Furthermore, in this OSE application scenario, the structured expression unit is the Pump statement block proposed in the above embodiments.

[0107] It should be noted that this application can be implemented in software and / or a combination of software and hardware, for example, it can be implemented using an application-specific integrated circuit (ASIC), a general-purpose computer or any other similar hardware device.

[0108] In one embodiment, the software program of this application can be executed by a processor to implement the steps or functions described above.

[0109] Similarly, the software program (including related data structures) of this application can be stored in a computer-readable recording medium, which includes permanent and non-permanent, removable and non-removable media. Information storage can be achieved by any method or technology, and the information can be computer-readable instructions, data structures, program modules or other data.

[0110] Furthermore, computer-readable recording media 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 technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transfer medium, which can be used to store information that can be accessed by a computing device.

[0111] As defined in this article, computer-readable media do not include non-transitory computer-readable media, such as modulated data signals and carrier waves.

[0112] In addition, some steps or functions of this application can be implemented in hardware, for example, as a circuit that works with a processor to perform the various steps or functions.

[0113] In addition, a portion of this application can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to this application through the operation of the computer.

[0114] The program instructions that invoke the methods of this application may be stored in a fixed or removable recording medium, and / or transmitted via a data stream in a broadcast or other signal carrying medium, and / or stored in the working memory of a computer device operating according to the program instructions.

[0115] Hereinafter, one embodiment of this application includes a processing system for implementing asynchronous callbacks, comprising: a processor and a memory, wherein the memory stores a computer program, and the computer program, when executed by the processor, triggers the system to run methods and / or technical solutions based on the foregoing embodiments of this application.

[0116] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0117] It should be noted that the above embodiments can be freely combined as needed. The above are merely preferred embodiments of the present invention; it should be observed that those skilled in the art can make several improvements and modifications without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.< / json> < / response> < / json> < / json> < / response> < / response> < / json> < / json> < / response> < / response> < / json> < / json> < / response> < / json> < / json> < / response>

Claims

1. A processing method for implementing asynchronous callbacks, characterized in that, when executed in a computer system, Based on a structured expression unit, at least one callback function is invoked in at least one target function call through the following steps, wherein the structured expression unit includes at least an identifier declaration section, a target function declaration section, a callback parameter declaration section, and a callback function declaration section: Based on the aforementioned identifier declaration section, at least one structured expression unit in the source program is identified, and the following steps are further performed on any structured expression unit: The structured representation unit is parsed to obtain the target function declaration, the callback parameter declaration, and the callback function declaration. According to the analysis results, Generate asynchronous callback call code, in which the callback function is inserted into the parameter list of the target function call, and execute the asynchronous callback call code to implement the callback call; or A closure object for the callback function is constructed, and the closure object is inserted into the parameter list of the target function call. When the target function call meets a predetermined triggering condition, the closure object is called to execute the callback function, thereby realizing the callback call.

2. The processing method for implementing asynchronous callbacks according to claim 1, characterized in that, The identifier declaration section includes a starting identifier declaration section; In the source program, each of the starting identifier declaration sections is used to uniquely identify the starting position of a corresponding structured expression unit.

3. The processing method for implementing asynchronous callbacks according to claim 2, characterized in that, The step of identifying at least one structured expression unit in the source program based on the identifier declaration section includes the following steps: Scan and locate all the start identifier declaration sections in the source program, and based on each start identifier declaration section: Based on the context of the start identifier declaration section, determine its corresponding end identifier; The expression boundary of the corresponding structured expression unit is determined based on the start identifier declaration part and its corresponding end identifier.

4. The processing method for implementing asynchronous callbacks according to claim 3, characterized in that, The end marker is determined according to the following rules, based on the order of appearance: If, within the same statement block as the start identifier declaration, there are no executable statements or declarations affecting program semantics after the start identifier declaration and before the next start identifier declaration, then the first appearing next start identifier declaration is confirmed as the end identifier of the structured expression unit; otherwise... The end marker is any of the following that appears first: the end marker of the statement block, the end marker of the host function, or the end marker of the source file.

5. The processing method for implementing asynchronous callbacks according to claim 1, characterized in that, The structured expression unit also includes: The callback parameter positioning declaration section is used to indicate the insertion position of the callback function or the closure object in the parameter list of the target function call.

6. The processing method for implementing asynchronous callbacks according to claim 5, characterized in that, The callback parameter positioning declaration is represented in any structured expression unit as an ordinal number with a first symbol or a second symbol, wherein: Ordinal numbers with a first sign represent the insertion position starting from the first position of the parameter list, while ordinal numbers with a second sign represent the insertion position starting from the last position of the parameter list. Furthermore, the first symbol and the second symbol are different from each other in terms of glyph or code position, and can be uniquely distinguished at the lexical level.

7. The processing method for implementing asynchronous callbacks according to claim 5, characterized in that, The callback parameter positioning declaration section, in any structured expression unit, indicates that the insertion position is a preset insertion position by not showing it.

8. The processing method for implementing asynchronous callbacks according to claim 7, characterized in that, The preset insertion position is the last element of the parameter list of the target function call.

9. The processing method for implementing asynchronous callbacks according to claim 1, characterized in that, For any two consecutive structured expression units within any statement block in the source program, the callback calls of the two structured expression units are executed one by one according to their order of writing within the corresponding statement block.

10. A processing system for implementing asynchronous callbacks, characterized in that, include: A processor and a memory, wherein the memory stores a computer program that, when executed by the processor, implements the processing method for implementing asynchronous callbacks as described in any one of claims 1 to 9.