-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversion_actor.rs
107 lines (62 loc) · 2.43 KB
/
conversion_actor.rs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
use act_rs::{ActorFrontend, ActorState, HasInteractor, impl_mac_runtime_task_actor, DroppedIndicator, impl_default_on_enter_async, impl_default_on_exit_async, impl_default_on_enter_and_exit_async};
use act_rs::tokio::{RuntimeTaskActor, interactors::mspc::{SenderInteractor, channel}};
use act_rs::tokio::crossbeam::{NotfiyingArrayQueue, InputNotfiyingArrayQueue, OutputNotfiyingArrayQueue, get_notifying_array_queue_iowii, InputNotfiyingArrayQueueInteractor};
use tokio::sync::oneshot::Sender;
use escape_it_lib::escape_string;
use std::{marker::PhantomData, sync::Arc};
use tokio::runtime::{Runtime, Handle};
use act_rs::ActorInteractor;
pub enum ConversionActorMessage
{
//get time?
Convert(String, Sender<String>)
}
pub struct ConversionActorState
{
input_queue_input_interactor: InputNotfiyingArrayQueueInteractor<Option<ConversionActorMessage>>, //Sender
input_queue_output: OutputNotfiyingArrayQueue<Option<ConversionActorMessage>> //Reciver
}
impl ConversionActorState
{
pub fn new() -> Self
{
let (input_queue_input_interactor, input_queue_output) = get_notifying_array_queue_iowii(5);
Self
{
input_queue_input_interactor,
input_queue_output
}
}
impl_default_on_enter_and_exit_async!();
async fn run_async(&mut self, di: &DroppedIndicator) -> bool
{
let input_val = self.input_queue_output.pop_or_wait().await;
match input_val
{
Some(cam_val) =>
{
match cam_val
{
ConversionActorMessage::Convert(input, returner) =>
{
let escaped = escape_string(&input, true);
if let Err(err) = returner.send(escaped)
{
eprintln!("Error {}", err);
}
}
}
},
None => { /* Continue */ },
}
di.has_not_dropped()
}
}
impl HasInteractor<InputNotfiyingArrayQueueInteractor<Option<ConversionActorMessage>>> for ConversionActorState
{
fn get_interactor(&self) -> InputNotfiyingArrayQueueInteractor<Option<ConversionActorMessage>>
{
self.input_queue_input_interactor.clone()
}
}
impl_mac_runtime_task_actor!(InputNotfiyingArrayQueueInteractor<Option<ConversionActorMessage>>, ConversionActorState, ConversionActor);