ump-ng-server

Check-in Differences
Login

Check-in Differences

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Difference From ump-ng-server-0.1.1 To ump-ng-server-0.1.2

2024-01-28
15:09
Use closure to construct Handler. Remove the spawn_preinit() functions, since using a closure to construct the Handler makes it possible to accomplish the same thing, but less ugly. check-in: d485928620 user: jan tags: trunk
2024-01-21
18:37
Release maintenance. check-in: 5f420344bf user: jan tags: trunk, ump-ng-server-0.1.2
18:31
Add preinit variants of both thread and task spawners. check-in: e3a0f27d4a user: jan tags: trunk
2024-01-14
15:40
Add doc building workaround. check-in: d1cc34cf7f user: jan tags: trunk, ump-ng-server-0.1.1
15:39
Release maintenance. check-in: dc8322fb06 user: jan tags: trunk

Changes to Cargo.toml.

1
2
3
4
5
6
7
8
9
10
[package]
name = "ump-ng-server"
version = "0.1.1"
edition = "2021"
license = "0BSD"
categories = [ "concurrency", "asynchronous" ]
keywords = [ "channel", "threads", "sync", "message-passing" ]
repository = "https://repos.qrnch.tech/pub/ump-ng-server"
description = "Server message dispatch loop for ump-ng."
rust-version = "1.56"


|







1
2
3
4
5
6
7
8
9
10
[package]
name = "ump-ng-server"
version = "0.1.2"
edition = "2021"
license = "0BSD"
categories = [ "concurrency", "asynchronous" ]
keywords = [ "channel", "threads", "sync", "message-passing" ]
repository = "https://repos.qrnch.tech/pub/ump-ng-server"
description = "Server message dispatch loop for ump-ng."
rust-version = "1.56"

Changes to src/lib.rs.

38
39
40
41
42
43
44

45

46
47



48
49
50
51



52
53
54
55
56
57

#[cfg(feature = "tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
pub mod task;

pub mod thread;


pub use ump_ng::{self, channel, Client, MsgType, ReplyContext, WeakClient};


pub use thread::{spawn as spawn_thread, Handler as ThreadedHandler};




#[cfg(feature = "tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
pub use task::{spawn as spawn_task, Handler as AsyncHandler};




#[cfg(feature = "tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
pub use async_trait::async_trait;

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :







>
|
>

|
>
>
>



|
>
>
>






38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

#[cfg(feature = "tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
pub mod task;

pub mod thread;

pub use ump_ng::{
  self, channel, Client, MsgType, ReplyContext, Server, WeakClient
};

pub use thread::{
  spawn as spawn_thread, spawn_preinit as spawn_thread_preinit,
  Handler as ThreadedHandler
};

#[cfg(feature = "tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
pub use task::{
  spawn as spawn_task, spawn_preinit as spawn_task_preinit,
  Handler as AsyncHandler
};

#[cfg(feature = "tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
pub use async_trait::async_trait;

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :

Changes to src/task.rs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
use std::ops::ControlFlow;

use tokio::task::{self, JoinHandle};

use async_trait::async_trait;

use super::{channel, Client, MsgType, ReplyContext};

#[async_trait]
pub trait Handler<P, S, R, E, RV> {
  /// Optional initialization callback.
  ///
  /// This is called on the dispatcher task before the main message
  /// processing loop is entered.






|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
use std::ops::ControlFlow;

use tokio::task::{self, JoinHandle};

use async_trait::async_trait;

use super::{channel, Client, MsgType, ReplyContext, Server};

#[async_trait]
pub trait Handler<P, S, R, E, RV> {
  /// Optional initialization callback.
  ///
  /// This is called on the dispatcher task before the main message
  /// processing loop is entered.
78
79
80
81
82
83
84




































85
    };
    handler.term(ret)
  });

  (client, jh)
}





































// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
    };
    handler.term(ret)
  });

  (client, jh)
}


/// Spawn a task to run a pre-initialized handler.
///
/// It is assumed that the caller has initialized the handler, thus its
/// `init()` method will not be called.
pub fn spawn_preinit<P, S, R, E, RV>(
  server: Server<P, S, R, E>,
  mut handler: impl Handler<P, S, R, E, RV> + Send + 'static
) -> JoinHandle<Option<RV>>
where
  P: 'static + Send,
  S: 'static + Send,
  R: 'static + Send,
  E: 'static + Send,
  RV: 'static + Send
{
  task::spawn(async move {
    let ret = loop {
      match server.async_wait().await {
        Ok(msg) => match msg {
          MsgType::Put(m) => match handler.post(m).await {
            ControlFlow::Continue(_) => {}
            ControlFlow::Break(rv) => break Some(rv)
          },
          MsgType::Request(m, rctx) => match handler.req(m, rctx).await {
            ControlFlow::Continue(_) => {}
            ControlFlow::Break(rv) => break Some(rv)
          }
        },
        Err(_) => break None
      }
    };
    handler.term(ret)
  })
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :

Changes to src/thread.rs.

1
2
3
4
5
6
7
8
9
10
11
12
13
use std::{
  ops::ControlFlow,
  thread::{self, JoinHandle}
};

use super::{channel, Client, MsgType, ReplyContext};

pub trait Handler<P, S, R, E, RV> {
  /// Optional initialization callback.
  ///
  /// This is called on the dispatcher thread before the main message
  /// processing loop is entered.
  #[allow(unused_variables)]





|







1
2
3
4
5
6
7
8
9
10
11
12
13
use std::{
  ops::ControlFlow,
  thread::{self, JoinHandle}
};

use super::{channel, Client, MsgType, ReplyContext, Server};

pub trait Handler<P, S, R, E, RV> {
  /// Optional initialization callback.
  ///
  /// This is called on the dispatcher thread before the main message
  /// processing loop is entered.
  #[allow(unused_variables)]
72
73
74
75
76
77
78

































































79
    };
    handler.term(ret)
  });

  (client, jh)
}


































































// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    };
    handler.term(ret)
  });

  (client, jh)
}


/// Spawn a thread to run a pre-initialized handler.
///
/// It is assumed that the caller has initialized the handler, thus its
/// `init()` method will not be called.
///
/// ```
/// use std::ops::ControlFlow;
/// use ump_ng_server::{ump_ng, spawn_thread_preinit, ThreadedHandler,
///   ReplyContext};
/// let (server, client) = ump_ng::channel::<(), (), (), ()>();
///
/// struct MyHandler {
///   wclnt: ump_ng::WeakClient<(), (), (), ()>
/// }
/// impl ThreadedHandler<(), (), (), (), ()> for MyHandler {
///   fn post(&mut self, _: ()) -> ControlFlow<(), ()> {
///     ControlFlow::Continue(())
///   }
///   fn req(&mut self, _: (), rctx: ReplyContext<(), ()>)
///     -> ControlFlow<(), ()> {
///     ControlFlow::Continue(())
///   }
/// }
/// let handler = MyHandler {
///   wclnt: client.weak()
/// };
/// let jh = spawn_thread_preinit(server, handler);
///
/// // drop client to force dispatch loop to terminate
/// drop(client);
///
/// jh.join();
/// ```
pub fn spawn_preinit<P, S, R, E, RV>(
  server: Server<P, S, R, E>,
  mut handler: impl Handler<P, S, R, E, RV> + Send + 'static
) -> JoinHandle<Option<RV>>
where
  P: 'static + Send,
  S: 'static + Send,
  R: 'static + Send,
  E: 'static + Send,
  RV: 'static + Send
{
  thread::spawn(move || {
    let ret = loop {
      match server.wait() {
        Ok(msg) => match msg {
          MsgType::Put(m) => match handler.post(m) {
            ControlFlow::Continue(_) => {}
            ControlFlow::Break(rv) => break Some(rv)
          },
          MsgType::Request(m, rctx) => match handler.req(m, rctx) {
            ControlFlow::Continue(_) => {}
            ControlFlow::Break(rv) => break Some(rv)
          }
        },
        Err(_) => break None
      }
    };
    handler.term(ret)
  })
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :

Changes to www/changelog.md.

1
2
3
4
5
6
7
8
9
10
11
12













13
14
15
16
17
18
19
# Change Log

## [Unreleased]

[Details](/vdiff?from=ump-ng-server-0.1.1&to=trunk)

### Added

### Changed

### Removed














---

## [0.1.1] - 2024-01-14

[Details](/vdiff?from=ump-ng-server-0.1.0&to=ump-ng-server-0.1.1)

### Changed




|







>
>
>
>
>
>
>
>
>
>
>
>
>







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
# Change Log

## [Unreleased]

[Details](/vdiff?from=ump-ng-server-0.1.2&to=trunk)

### Added

### Changed

### Removed

---

## [0.1.2] - 2024-01-21

[Details](/vdiff?from=ump-ng-server-0.1.1&to=ump-ng-server-0.1.2)

### Added

- There are new spawn thread/task functions (with the suffix `_preinit`) that
  take in a ump-ng `Server` and assumes that the message handler has already
  been initialized.  This is useful if the handler itself needs contain a
  (weak) client reference, and one does not wish to store it in an `Option`.

---

## [0.1.1] - 2024-01-14

[Details](/vdiff?from=ump-ng-server-0.1.0&to=ump-ng-server-0.1.1)

### Changed

Changes to www/index.md.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
# ump-ng-server

The _ump-ng-server_ crate is a server message dispatch abstraction for
[ump-ng](https://repos.qrnch.tech/pub/ump-ng).


## Feature labels in documentation

The crate's documentation uses automatically generated feature labels, which
currently requires nightly featuers.  To build the documentation locally use:

```

RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features
```


## Change log

The details of changes can always be found in the timeline, but for a
high-level view of changes between released versions there's a manually












>
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# ump-ng-server

The _ump-ng-server_ crate is a server message dispatch abstraction for
[ump-ng](https://repos.qrnch.tech/pub/ump-ng).


## Feature labels in documentation

The crate's documentation uses automatically generated feature labels, which
currently requires nightly featuers.  To build the documentation locally use:

```
$ RUSTFLAGS="--cfg docsrs" RUSTDOCFLAGS="--cfg docsrs" \
cargo +nightly doc --all-features
```


## Change log

The details of changes can always be found in the timeline, but for a
high-level view of changes between released versions there's a manually