Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
refactor: prefer impl trait in db.mod when possible
Browse files Browse the repository at this point in the history
Issue #1238
  • Loading branch information
pjenvey committed May 21, 2018
1 parent fd48405 commit 8b6dd7d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
37 changes: 19 additions & 18 deletions autopush_rs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,17 @@ where

let AwaitHello { data, tx, rx, .. } = hello.take();
let connected_at = ms_since_epoch();
transition!(AwaitProcessHello {
response: data.srv.ddb.hello(
let response = Box::new(data.srv.ddb.hello(
&connected_at,
uaid.as_ref(),
&data.srv.opts.router_table_name,
&data.srv.opts.router_url,
&data.srv.opts.message_table_names,
&data.srv.opts.current_message_month,
&data.srv.metrics,
),
));
transition!(AwaitProcessHello {
response,
data,
interested_broadcasts: services,
tx,
Expand Down Expand Up @@ -567,7 +568,7 @@ where

#[state_machine_future(transitions(DetermineAck))]
AwaitIncrementStorage {
ddb_response: MyFuture<UpdateItemOutput>,
response: MyFuture<UpdateItemOutput>,
data: AuthClientData<T>,
},

Expand Down Expand Up @@ -687,17 +688,17 @@ where
transition!(CheckStorage { data });
} else if all_acked && webpush.flags.rotate_message_table {
debug!("Triggering migration");
let response = data.srv.ddb.migrate_user(
let response = Box::new(data.srv.ddb.migrate_user(
&webpush.uaid,
&webpush.message_month,
&data.srv.opts.current_message_month,
&data.srv.opts.router_table_name,
);
));
transition!(AwaitMigrateUser { response, data });
} else if all_acked && webpush.flags.reset_uaid {
let response = data.srv
let response = Box::new(data.srv
.ddb
.drop_uaid(&data.srv.opts.router_table_name, &webpush.uaid);
.drop_uaid(&data.srv.opts.router_table_name, &webpush.uaid));
transition!(AwaitDropUser { response, data });
}
transition!(AwaitInput { data })
Expand Down Expand Up @@ -763,16 +764,16 @@ where
// register does
let uaid = webpush.uaid;
let message_month = webpush.message_month.clone();
let fut = data.srv.ddb.unregister(
let response = Box::new(data.srv.ddb.unregister(
&uaid,
&channel_id,
&message_month,
code.unwrap_or(200),
&data.srv.metrics,
);
));
transition!(AwaitUnregister {
channel_id,
response: fut,
response,
data,
});
}
Expand Down Expand Up @@ -804,7 +805,7 @@ where
let my_fut = data.srv.ddb.delete_message(&message_month, &webpush.uaid, &n);
Some(Box::new(call.and_then(move |_| my_fut)))
} else {
Some(data.srv.ddb.delete_message(&message_month, &webpush.uaid, &n))
Some(Box::new(data.srv.ddb.delete_message(&message_month, &webpush.uaid, &n)))
}
}
continue;
Expand Down Expand Up @@ -853,13 +854,13 @@ where
.unacked_stored_highest
.ok_or("unacked_stored_highest unset")?
.to_string();
let ddb_response = increment_storage.data.srv.ddb.increment_storage(
let response = Box::new(increment_storage.data.srv.ddb.increment_storage(
&webpush.message_month,
&webpush.uaid,
&timestamp,
);
));
transition!(AwaitIncrementStorage {
ddb_response,
response,
data: increment_storage.take().data,
})
}
Expand All @@ -868,7 +869,7 @@ where
await_increment_storage: &'a mut RentToOwn<'a, AwaitIncrementStorage<T>>,
) -> Poll<AfterAwaitIncrementStorage<T>, Error> {
debug!("State: AwaitIncrementStorage");
try_ready!(await_increment_storage.ddb_response.poll());
try_ready!(await_increment_storage.response.poll());
let AwaitIncrementStorage { data, .. } = await_increment_storage.take();
let webpush = data.webpush.clone();
webpush.borrow_mut().flags.increment_storage = false;
Expand All @@ -880,15 +881,15 @@ where
) -> Poll<AfterCheckStorage<T>, Error> {
debug!("State: CheckStorage");
let CheckStorage { data } = check_storage.take();
let response = {
let response = Box::new({
let webpush = data.webpush.borrow();
data.srv.ddb.check_storage(
&webpush.message_month.clone(),
&webpush.uaid,
webpush.flags.include_topic,
webpush.unacked_stored_highest,
)
};
});
transition!(AwaitCheckStorage { response, data })
}

Expand Down
29 changes: 14 additions & 15 deletions autopush_rs/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl DynamoStorage {
table_name: &str,
uaid: &Uuid,
timestamp: &str,
) -> MyFuture<UpdateItemOutput> {
) -> impl Future<Item = UpdateItemOutput, Error = Error> {
let ddb = self.ddb.clone();
let expiry = sec_since_epoch() + 2 * MAX_EXPIRY;
let attr_values = hashmap! {
Expand Down Expand Up @@ -120,7 +120,7 @@ impl DynamoStorage {
message_table_names: &[String],
current_message_month: &str,
metrics: &StatsdClient,
) -> MyFuture<HelloResponse> {
) -> impl Future<Item = HelloResponse, Error = Error> {
let router_table_name = router_table_name.to_string();
let response: MyFuture<(HelloResponse, Option<DynamoDbUser>)> = if let Some(uaid) = uaid {
commands::lookup_user(
Expand All @@ -145,7 +145,7 @@ impl DynamoStorage {
let ddb = self.ddb.clone();
let router_url = router_url.to_string();
let connected_at = *connected_at;
let response = response.and_then(move |(mut hello_response, user_opt)| -> MyFuture<_> {
let response = response.and_then(move |(mut hello_response, user_opt)| {
let hello_message_month = hello_response.message_month.clone();
let user = user_opt.unwrap_or_else(|| DynamoDbUser {
current_month: Some(hello_message_month),
Expand All @@ -156,7 +156,7 @@ impl DynamoStorage {
let uaid = user.uaid;
let mut err_response = hello_response.clone();
err_response.connected_at = connected_at;
let ddb_response = commands::register_user(ddb, &user, router_table_name.as_ref())
commands::register_user(ddb, &user, router_table_name.as_ref())
.and_then(move |result| {
debug!("Success adding user, item output: {:?}", result);
hello_response.uaid = Some(uaid);
Expand All @@ -165,11 +165,10 @@ impl DynamoStorage {
.or_else(move |e| {
debug!("Error registering user: {:?}", e);
future::ok(err_response)
});
Box::new(ddb_response)
})
});
metrics.incr("ua.command.hello").ok();
Box::new(response)
response
}

pub fn register(
Expand Down Expand Up @@ -203,7 +202,7 @@ impl DynamoStorage {
Box::new(response)
}

pub fn drop_uaid(&self, table_name: &str, uaid: &Uuid) -> MyFuture<()> {
pub fn drop_uaid(&self, table_name: &str, uaid: &Uuid) -> impl Future<Item = (), Error = Error> {
commands::drop_user(self.ddb.clone(), uaid, table_name)
.and_then(move |_| future::ok(()))
.chain_err(|| "Unable to drop user record")
Expand All @@ -216,7 +215,7 @@ impl DynamoStorage {
message_month: &str,
code: u32,
metrics: &StatsdClient,
) -> MyFuture<bool> {
) -> impl Future<Item = bool, Error = Error> {
let response =
commands::unregister_channel_id(self.ddb.clone(), uaid, channel_id, message_month)
.and_then(|_| future::ok(true))
Expand All @@ -226,7 +225,7 @@ impl DynamoStorage {
.with_tag("code", &code.to_string())
.send()
.ok();
Box::new(response)
response
}

/// Migrate a user to a new month table
Expand All @@ -236,7 +235,7 @@ impl DynamoStorage {
message_month: &str,
current_message_month: &str,
router_table_name: &str,
) -> MyFuture<()> {
) -> impl Future<Item = (), Error = Error> {
let uaid = *uaid;
let ddb = self.ddb.clone();
let ddb2 = self.ddb.clone();
Expand Down Expand Up @@ -264,7 +263,7 @@ impl DynamoStorage {
uaid: &Uuid,
message_month: &str,
messages: Vec<Notification>,
) -> MyFuture<()> {
) -> impl Future<Item = (), Error = Error> {
let ddb = self.ddb.clone();
let put_items: Vec<WriteRequest> = messages
.into_iter()
Expand Down Expand Up @@ -304,7 +303,7 @@ impl DynamoStorage {
table_name: &str,
uaid: &Uuid,
notif: &Notification,
) -> MyFuture<()> {
) -> impl Future<Item = (), Error = Error> {
let ddb = self.ddb.clone();
let delete_input = DeleteItemInput {
table_name: table_name.to_string(),
Expand All @@ -328,7 +327,7 @@ impl DynamoStorage {
uaid: &Uuid,
include_topic: bool,
timestamp: Option<u64>,
) -> MyFuture<CheckStorageResponse> {
) -> impl Future<Item = CheckStorageResponse, Error = Error> {
let response: MyFuture<FetchMessageResponse> = if include_topic {
Box::new(commands::fetch_messages(
self.ddb.clone(),
Expand Down Expand Up @@ -383,6 +382,6 @@ impl DynamoStorage {
});
Box::new(next_query)
});
Box::new(response)
response
}
}

0 comments on commit 8b6dd7d

Please sign in to comment.