Skip to content

Commit

Permalink
[node] Update async_hooks according to renaming done in 8.2.0 (Defini…
Browse files Browse the repository at this point in the history
…telyTyped#18530)

- currentId() => executionAsyncId()
- triggerId() => triggerAsyncId()

see nodejs/node#13490
  • Loading branch information
Flarna authored and milosdanilov committed Aug 5, 2017
1 parent c17ab6b commit 33f4fa3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions types/node/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5748,22 +5748,26 @@ declare module "async_hooks" {
/**
* Returns the asyncId of the current execution context.
*/
export function executionAsyncId(): number;
/// @deprecated - replaced by executionAsyncId()
export function currentId(): number;

/**
* Returns the ID of the resource responsible for calling the callback that is currently being executed.
*/
export function triggerAsyncId(): number;
/// @deprecated - replaced by triggerAsyncId()
export function triggerId(): number;

export interface HookCallbacks {
/**
* Called when a class is constructed that has the possibility to emit an asynchronous event.
* @param asyncId a unique ID for the async resource
* @param type the type of the async resource
* @param triggerId the unique ID of the async resource in whose execution context this async resource was created
* @param triggerAsyncId the unique ID of the async resource in whose execution context this async resource was created
* @param resource reference to the resource representing the async operation, needs to be released during destroy
*/
init?(asyncId: number, type: string, triggerId: number, resource: Object): void;
init?(asyncId: number, type: string, triggerAsyncId: number, resource: Object): void;

/**
* When an asynchronous operation is initiated or completes a callback is called to notify the user.
Expand Down
5 changes: 4 additions & 1 deletion types/node/node-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2801,7 +2801,7 @@ client.listbreakpoints((err, body, packet) => { });
////////////////////////////////////////////////////
namespace async_hooks_tests {
const hooks: async_hooks.HookCallbacks = {
init: (asyncId: number, type: string, triggerId: number, resource: object) => void {},
init: (asyncId: number, type: string, triggerAsyncId: number, resource: object) => void {},
before: (asyncId: number) => void {},
after: (asyncId: number) => void {},
destroy: (asyncId: number) => void {}
Expand All @@ -2810,4 +2810,7 @@ namespace async_hooks_tests {
const asyncHook = async_hooks.createHook(hooks);

asyncHook.enable().disable().enable();

const tId: number = async_hooks.triggerAsyncId();
const eId: number = async_hooks.executionAsyncId();
}

0 comments on commit 33f4fa3

Please sign in to comment.