Skip to content

Commit bb90837

Browse files
authored
Merge pull request #103 from neon-bindings/kv/update-neon
Update to latest Neon
2 parents 7a466b2 + 8c5b3c6 commit bb90837

23 files changed

Lines changed: 1130 additions & 996 deletions

File tree

Cargo.lock

Lines changed: 890 additions & 394 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "3"
23
members = [
34
"examples/async-sqlite",
45
"examples/cpu-count",
@@ -7,8 +8,9 @@ members = [
78
"examples/tokio-fetch",
89
]
910

11+
[workspace.dependencies.neon]
12+
version = "1.2.0-alpha.0"
13+
features = ["tokio"]
14+
1015
[profile.release]
1116
lto = true
12-
13-
[patch.crates-io]
14-
neon = { git = "https://github.com/neon-bindings/neon.git" }

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
Examples and common patterns for [Neon][neon].
66

7-
All examples are for [`napi-backend`][napi-migration]. For examples using `legacy-backend` see the [`legacy`][legacy] branch.
8-
97
[neon]: https://github.com/neon-bindings/neon
10-
[napi-migration]: https://github.com/neon-bindings/neon/blob/main/MIGRATION_GUIDE.md#n-api-migration-guide
11-
[legacy]: https://github.com/neon-bindings/examples/tree/legacy
128

139
## Table of Contents
1410

examples/async-sqlite/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ name = "async-sqlite"
33
version = "0.1.0"
44
description = "Neon Async SQLite"
55
license = "MIT"
6-
edition = "2018"
6+
edition = "2024"
77
exclude = ["index.node"]
88

99
[lib]
1010
crate-type = ["cdylib"]
1111

1212
[dependencies]
13-
neon = "1"
14-
rusqlite = "0.25"
13+
neon.workspace = true
14+
rusqlite = "0.37.0"

examples/async-sqlite/README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The Async SQLite example implements a simple database in Rust with a JavaScript
55
## Usage
66

77
```js
8-
const Database = require(".");
8+
const { Database } = require(".");
99

1010
(async () => {
1111
const db = new Database();
@@ -31,25 +31,18 @@ Since SQLite is naturally single threaded, our application does not benefit from
3131

3232
Once the database thread is spawned, the JavaScript main thread needs a way to communicate with it. A [multi-producer, single-consumer (mpsc)][mpsc] channel is created. The receiving end is owned by the database thread and the sender is held by JavaScript.
3333

34-
#### `JsBox`
34+
#### `#[neon::export(class)]`
3535

36-
Rust data cannot be directly held by JavaScript. The [`JsBox`][jsbox] provides a mechanism for allowing JavaScript to hold a reference to Rust data and later access it again from Rust.
36+
The Rust sender side of the channel is held in a JavaScript [class][class]. It can be referenced later in methods.
3737

3838
#### Rust and Neon Channels
3939

4040
The mpsc channel provides a way for the JavaScript main thread to communicate with the database thread, but it is one-way. In order to complete the callback, the database thread must be able to communicate with the JavaScript main thread. [`neon::event::Channel`][channel] provides a channel for sending these events back.
4141

42-
#### `Root`
43-
44-
The last issue to solve is sending a reference to the JavaScript callback to the database thread and back again before finally calling it. [Handles][handle] to JavaScript values are not `Send`; they cannot escape the scope that created them. The reason they cannot be passed to other threads is because when control is returned back to the JavaScript engine, the garbage collector may determine they are no longer used and free the value.
45-
46-
A [`Root`][root] is a special handle to a JavaScript value that prevents the value from being freed as long as the `Root` has not been dropped. By placing the callback in a `Root`, it can be safely sent across threads and finally accessed and called when back on the JavaScript main thread.
47-
4842
### JavaScript
4943

5044
[thread]: https://doc.rust-lang.org/std/thread/
5145
[mpsc]: https://doc.rust-lang.org/std/sync/mpsc/index.html
52-
[jsbox]: https://docs.rs/neon/latest/neon/types/struct.JsBox.html
46+
[class]: https://docs.rs/neon/latest/neon/attr.class.html
5347
[channel]: https://docs.rs/neon/latest/neon/event/struct.Channel.html
5448
[handle]: https://docs.rs/neon/latest/neon/handle/struct.Handle.html
55-
[root]: https://docs.rs/neon/latest/neon/handle/struct.Root.html

examples/async-sqlite/index.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

examples/async-sqlite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "async-sqlite",
33
"version": "0.1.0",
44
"description": "Neon Async SQLite",
5-
"main": "index.js",
5+
"main": "index.node",
66
"scripts": {
77
"build": "cargo-cp-artifact -nc index.node -- cargo build --message-format=json-render-diagnostics",
88
"install": "npm run build",

0 commit comments

Comments
 (0)