1# CallbackScope
2
3There are cases (for example, resolving promises) where it is necessary to have
4the equivalent of the scope associated with a callback in place when making
5certain Node-API calls.
6
7## Methods
8
9### Constructor
10
11Creates a new callback scope on the stack.
12
13```cpp
14Napi::CallbackScope::CallbackScope(napi_env env, napi_callback_scope scope);
15```
16
17- `[in] env`: The environment in which to create the `Napi::CallbackScope`.
18- `[in] scope`: The pre-existing `napi_callback_scope` or `Napi::CallbackScope`.
19
20### Constructor
21
22Creates a new callback scope on the stack.
23
24```cpp
25Napi::CallbackScope::CallbackScope(napi_env env, napi_async_context context);
26```
27
28- `[in] env`: The environment in which to create the `Napi::CallbackScope`.
29- `[in] async_context`: The pre-existing `napi_async_context` or `Napi::AsyncContext`.
30
31### Destructor
32
33Deletes the instance of `Napi::CallbackScope` object.
34
35```cpp
36virtual Napi::CallbackScope::~CallbackScope();
37```
38
39### Env
40
41```cpp
42Napi::Env Napi::CallbackScope::Env() const;
43```
44
45Returns the `Napi::Env` associated with the `Napi::CallbackScope`.
46
47## Operator
48
49```cpp
50Napi::CallbackScope::operator napi_callback_scope() const;
51```
52
53Returns the Node-API `napi_callback_scope` wrapped by the `Napi::CallbackScope`
54object. This can be used to mix usage of the C Node-API and node-addon-api.
55