Italian Translation Report: Node.js [Part 19 - 1349 words]

Aug 2nd, 2018
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. is an object that represents the actual async resource that has been initialized.
  2. This can contain useful information that can vary based on the value of
  3. For instance, for the resource type, provides the hostname used when looking up the IP address for the hostname in
  4. The API for accessing this information is currently not considered public, but using the Embedder API, users can provide and document their own resource objects.
  5. For example, such a resource object could contain the SQL query being executed.
  6. In the case of Promises, the object will have property that refers to the that is being initialized, and an property, set toif the promise has a parent promise, and otherwise.
  7. For example, in the case of is considered a parent of
  8. Here, is considered a chained promise.
  9. In some cases the resource object is reused for performance reasons, it is thus not safe to use it as a key in a or add properties to it.
  10. Asynchronous context example
  11. The following is an example with additional information about the calls to between the and calls, specifically what the callback to will look like.
  12. The output formatting is slightly more elaborate to make calling context easier to see.
  13. Let's wait 10ms before logging the server started.
  14. Output from only starting the server:
  15. As illustrated in the example, and each specify the value of the current execution context; which is delineated by calls to and
  16. Only using to graph resource allocation results in the following:
  17. The is not part of this graph, even though it was the reason for being called.
  18. This is because binding to a port without a hostname is a operation, but to maintain a completely asynchronous API the user's callback is placed in a
  19. The graph only shows when a resource was created, not why, so to track the why use
  20. When an asynchronous operation is initiated (such as a TCP server receiving a new connection) or completes (such as writing data to disk) a callback is called to notify the user.
  21. The callback is called just before said callback is executed.
  22. is the unique identifier assigned to the resource about to execute the callback.
  23. The callback will be called 0 to N times.
  24. The callback will typically be called 0 times if the asynchronous operation was cancelled or, for example, if no connections are received by a TCP server.
  25. Persistent asynchronous resources like a TCP server will typically call the callback multiple times, while other operations like will call it only once.
  26. Called immediately after the callback specified in is completed.
  27. If an uncaught exception occurs during execution of the callback, then will run the event is emitted or a handler runs.
  28. Called after the resource corresponding to is destroyed.
  29. It is also called asynchronously from the embedder API
  30. Some resources depend on garbage collection for cleanup, so if a reference is made to the object passed to it is possible that will never be called, causing a memory leak in the application.
  31. If the resource does not depend on garbage collection, then this will not be an issue.
  32. Called when the function passed to the constructor is invoked (either directly or through other means of resolving a promise).
  33. Note that does not do any observable synchronous work.
  34. The is not necessarily fulfilled or rejected at this point if the was resolved by assuming the state of another
  35. calls the following callbacks:
  36. Returns: The of the current execution context.
  37. Useful to track when something calls.
  38. The ID returned from is related to execution timing, not causality (which is covered by):
  39. Returns the ID of the server, not of the new connection, because the callback runs in the execution scope of the server's
  40. Returns the ID of a because all callbacks passed to are wrapped in a
  41. Note that promise contexts may not get precise by default.
  42. See the section on
  43. The ID of the resource responsible for calling the callback that is currently being executed.
  44. The resource that caused (or triggered) this callback to be called was that of the new connection.
  45. Thus the return value of is the of
  46. Even though all callbacks passed to are wrapped in a the callback itself exists because the call to the server's was made.
  47. Note that promise contexts may not get valid by default.
  48. By default, promise executions are not assigned due to the relatively expensive nature of the provided by
  49. V8.
  50. This means that programs using promises or will not get correct execution and trigger ids for promise callback contexts by default.
  51. Here's an example:
  52. produces
  53. Observe that the callback claims to have executed in the context of the outer scope even though there was an asynchronous hop involved.
  54. Also note that the value is, which means that we are missing context about the resource that caused (triggered) the callback to be executed.
  55. Installing async hooks via enables promise execution tracking.
  56. forces PromiseHooks to be enabled.
  57. In this example, adding any actual hook function enabled the tracking of promises.
  58. There are two promises in the example above; the promise created by and the promise returned by the call to
  59. In the example above, the first promise got the and the latter got
  60. During the execution of the callback, we are executing in the context of promise with
  61. This promise was triggered by async resource
  62. Another subtlety with promises is that and callbacks are run only on chained promises.
  63. That means promises not created by will not have the and callbacks fired on them.
  64. For more details see the details of the V8 API.
  65. Library developers that handle their own asynchronous resources performing tasks like I/O, connection pooling, or managing callback queues may use the JavaScript API so that all the appropriate callbacks are called.
  66. The class is designed to be extended by the embedder's async resources.
  67. Using this, users can easily trigger the lifetime events of their own resources.
  68. The hook will trigger when an is instantiated.
  69. The following is an overview of the API.
  70. is meant to be extended.
  71. Instantiating a new also triggers init.
  72. If triggerAsyncId is omitted then is used.
  73. Run a function in the execution context of the resource.
  74. This will
  75. // * establish the context of the resource
  76. // * trigger the callbacks
  77. // * call the provided function with the supplied arguments
  78. // * trigger the callbacks
  79. // * restore the original execution context
  80. // Call
  81. Return the unique ID assigned to the AsyncResource instance.
  82. Deprecated: Use instead.
  83. The type of async event.
  84. The ID of the execution context that created this async event.
  85. Disables automatic when the object is garbage collected.
  86. This usually does not need to be set (even if is called manually), unless the resource's is retrieved and the sensitive API's is called with it.
  87. The function to call in the execution context of this async resource.
  88. The receiver to be used for the function call.
  89. Optional arguments to pass to the function.
  90. Call the provided function with the provided arguments in the execution context of the async resource. This will establish the context, trigger the, call the function, trigger the, and then restore the original execution context.
  91. Call all to notify that a new asynchronous execution context is being entered.
  92. If nested calls to are made, the stack of will be tracked and properly unwound.
  93. and calls must be unwound in the same order that they are called.
  94. Otherwise, an unrecoverable exception will occur and the process will abort.
  95. For this reason, the and APIs are considered deprecated.
  96. Please use, as it provides a much safer alternative.
  97. If nested calls to were made, then make sure the stack is unwound properly.
  98. Otherwise an error will be thrown.
  99. If the user's callback throws an exception, will automatically be called for all on the stack if the error is handled by a domain or handler.
  100. This should only ever be called once.
  101. An error will be thrown if it is called more than once.
  102. This must be manually called.
  103. If the resource is left to be collected by the GC then the will never be called.
  104. The same that is passed to the constructor.
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add to your ad blocker whitelist or disable your adblocking software.