-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: rewrite AsyncLocalStorage without async_hooks
PR-URL: #48528 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
- Loading branch information
Showing
29 changed files
with
658 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const { | ||
getContinuationPreservedEmbedderData, | ||
setContinuationPreservedEmbedderData, | ||
} = internalBinding('async_context_frame'); | ||
|
||
let enabled_; | ||
|
||
class AsyncContextFrame extends Map { | ||
constructor(store, data) { | ||
super(AsyncContextFrame.current()); | ||
this.set(store, data); | ||
} | ||
|
||
static get enabled() { | ||
enabled_ ??= require('internal/options') | ||
.getOptionValue('--experimental-async-context-frame'); | ||
return enabled_; | ||
} | ||
|
||
static current() { | ||
if (this.enabled) { | ||
return getContinuationPreservedEmbedderData(); | ||
} | ||
} | ||
|
||
static set(frame) { | ||
if (this.enabled) { | ||
setContinuationPreservedEmbedderData(frame); | ||
} | ||
} | ||
|
||
static exchange(frame) { | ||
const prior = this.current(); | ||
this.set(frame); | ||
return prior; | ||
} | ||
|
||
static disable(store) { | ||
const frame = this.current(); | ||
frame?.disable(store); | ||
} | ||
|
||
disable(store) { | ||
this.delete(store); | ||
} | ||
} | ||
|
||
module.exports = AsyncContextFrame; |
Oops, something went wrong.