File: callback_scope.md

package info (click to toggle)
node-addon-api 8.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,248 kB
  • sloc: cpp: 15,431; javascript: 5,631; ansic: 157; makefile: 7
file content (54 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# CallbackScope

There are cases (for example, resolving promises) where it is necessary to have
the equivalent of the scope associated with a callback in place when making
certain Node-API calls.

## Methods

### Constructor

Creates a new callback scope on the stack.

```cpp
Napi::CallbackScope::CallbackScope(napi_env env, napi_callback_scope scope);
```

- `[in] env`: The environment in which to create the `Napi::CallbackScope`.
- `[in] scope`: The pre-existing `napi_callback_scope` or `Napi::CallbackScope`.

### Constructor

Creates a new callback scope on the stack.

```cpp
Napi::CallbackScope::CallbackScope(napi_env env, napi_async_context context);
```

- `[in] env`: The environment in which to create the `Napi::CallbackScope`.
- `[in] async_context`: The pre-existing `napi_async_context` or `Napi::AsyncContext`.

### Destructor

Deletes the instance of `Napi::CallbackScope` object.

```cpp
virtual Napi::CallbackScope::~CallbackScope();
```

### Env

```cpp
Napi::Env Napi::CallbackScope::Env() const;
```

Returns the `Napi::Env` associated with the `Napi::CallbackScope`.

## Operator

```cpp
Napi::CallbackScope::operator napi_callback_scope() const;
```

Returns the Node-API `napi_callback_scope` wrapped by the `Napi::CallbackScope`
object. This can be used to mix usage of the C Node-API and node-addon-api.