Skip to content

Commit b603cd9

Browse files
authored
Merge pull request #77 from syohex/update-0.9
Update example to neon 0.9
2 parents 42564aa + 4ec08df commit b603cd9

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

Cargo.lock

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

examples/async-sqlite/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ crate-type = ["cdylib"]
1313
rusqlite = "0.25"
1414

1515
[dependencies.neon]
16-
version = "0.8"
16+
version = "0.9"
1717
default-features = false
1818
features = ["napi-6", "event-queue-api", "try-catch-api"]

examples/async-sqlite/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ Once the database thread is spawned, the JavaScript main thread needs a way to c
3535

3636
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.
3737

38-
#### Channels and `EventQueue`
38+
#### Rust and Neon Channels
3939

40-
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. [`EventQueue`][eventqueue] provides a channel for sending these events back.
40+
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

4242
#### `Root`
4343

@@ -49,7 +49,7 @@ A [`Root`][root] is a special handle to a JavaScript value that prevents the val
4949

5050
[thread]: https://doc.rust-lang.org/std/thread/
5151
[mpsc]: https://doc.rust-lang.org/std/sync/mpsc/index.html
52-
[jsbox]: https://docs.rs/neon/0.8.1-napi/neon/types/struct.JsBox.html
53-
[eventqueue]: https://docs.rs/neon/0.8.1-napi/neon/event/struct.EventQueue.html
54-
[handle]: https://docs.rs/neon/0.8.1-napi/neon/handle/struct.Handle.html
55-
[root]: https://docs.rs/neon/0.8.1-napi/neon/handle/struct.Root.html
52+
[jsbox]: https://docs.rs/neon/latest/neon/types/struct.JsBox.html
53+
[channel]: https://docs.rs/neon/latest/neon/event/struct.Channel.html
54+
[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/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::thread;
44
use neon::prelude::*;
55
use rusqlite::Connection;
66

7-
type DbCallback = Box<dyn FnOnce(&mut Connection, &EventQueue) + Send>;
7+
type DbCallback = Box<dyn FnOnce(&mut Connection, &Channel) + Send>;
88

99
// Wraps a SQLite connection a channel, allowing concurrent access
1010
struct Database {
@@ -41,11 +41,11 @@ impl Database {
4141
// Open a connection sqlite, this will be moved to the thread
4242
let mut conn = Connection::open_in_memory()?;
4343

44-
// Create an `EventQueue` for calling back to JavaScript. It is more efficient
45-
// to create a single queue and re-use it for all database callbacks.
46-
// The JavaScript process will not exit as long as this queue has not been
44+
// Create an `Channel` for calling back to JavaScript. It is more efficient
45+
// to create a single channel and re-use it for all database callbacks.
46+
// The JavaScript process will not exit as long as this channel has not been
4747
// dropped.
48-
let queue = cx.queue();
48+
let channel = cx.channel();
4949

5050
// Create a table in the in-memory database
5151
// In production code, this would likely be handled somewhere else
@@ -70,10 +70,10 @@ impl Database {
7070
while let Ok(message) = rx.recv() {
7171
match message {
7272
DbMessage::Callback(f) => {
73-
// The connection and queue are owned by the thread, but _lent_ to
73+
// The connection and channel are owned by the thread, but _lent_ to
7474
// the callback. The callback has exclusive access to the connection
7575
// for the duration of the callback.
76-
f(&mut conn, &queue);
76+
f(&mut conn, &channel);
7777
}
7878
// Immediately close the connection, even if there are pending messages
7979
DbMessage::Close => break,
@@ -92,7 +92,7 @@ impl Database {
9292

9393
fn send(
9494
&self,
95-
callback: impl FnOnce(&mut Connection, &EventQueue) + Send + 'static,
95+
callback: impl FnOnce(&mut Connection, &Channel) + Send + 'static,
9696
) -> Result<(), mpsc::SendError<DbMessage>> {
9797
self.tx.send(DbMessage::Callback(Box::new(callback)))
9898
}
@@ -136,15 +136,15 @@ impl Database {
136136
// Get the `this` value as a `JsBox<Database>`
137137
let db = cx.this().downcast_or_throw::<JsBox<Database>, _>(&mut cx)?;
138138

139-
db.send(move |conn, queue| {
139+
db.send(move |conn, channel| {
140140
let result = conn
141141
.execute(
142142
"INSERT INTO person (name) VALUES (?)",
143143
rusqlite::params![name],
144144
)
145145
.map(|_| conn.last_insert_rowid());
146146

147-
queue.send(move |mut cx| {
147+
channel.send(move |mut cx| {
148148
let callback = callback.into_inner(&mut cx);
149149
let this = cx.undefined();
150150
let args: Vec<Handle<JsValue>> = match result {
@@ -175,12 +175,12 @@ impl Database {
175175
// Get the `this` value as a `JsBox<Database>`
176176
let db = cx.this().downcast_or_throw::<JsBox<Database>, _>(&mut cx)?;
177177

178-
db.send(move |conn, queue| {
178+
db.send(move |conn, channel| {
179179
let result: Result<String, _> = conn
180180
.prepare("SELECT name FROM person WHERE id = ?")
181181
.and_then(|mut stmt| stmt.query_row(rusqlite::params![id], |row| row.get(0)));
182182

183-
queue.send(move |mut cx| {
183+
channel.send(move |mut cx| {
184184
let callback = callback.into_inner(&mut cx);
185185
let this = cx.undefined();
186186
let args: Vec<Handle<JsValue>> = match result {

examples/cpu-count/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ crate-type = ["cdylib"]
1313
num_cpus = "1"
1414

1515
[dependencies.neon]
16-
version = "0.8"
16+
version = "0.9"
1717
default-features = false
1818
features = ["napi-6"]

examples/hello-world/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ exclude = ["index.node"]
1010
crate-type = ["cdylib"]
1111

1212
[dependencies.neon]
13-
version = "0.8"
13+
version = "0.9"
1414
default-features = false
1515
features = ["napi-6"]

0 commit comments

Comments
 (0)