Skip to content

Commit 3a52db8

Browse files
committed
clean up the code warnings
1 parent 6ae5b83 commit 3a52db8

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/queue/q_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl RequestQueue for UnifiedQueue {
1111
/// - Ok(Some(MatchResult)) if an immediate match was found
1212
/// - Ok(None) if no match was found and the request was added to the queue
1313
/// - Err(BumpError) if there was an error adding the request
14-
async fn add_request(&self, mut request: QueuedRequest) -> Result<Option<MatchResult>, BumpError> {
14+
async fn add_request(&self, mut request: QueuedRequest) -> Result<Option<(MatchResult, MatchResult)>, BumpError> {
1515
// Ensure the request is in Active state
1616
request.state = RequestState::Active;
1717
request.reserved_by = None;
@@ -101,7 +101,7 @@ impl RequestQueue for UnifiedQueue {
101101
// Note: We don't need to send to the channel here anymore
102102
// as atomic_match now handles notifying both channels
103103

104-
return Ok(Some(match_result));
104+
return Ok(Some((match_result.0, match_result.1)));
105105
},
106106
Err(e) => {
107107
// Match failed - log and continue
@@ -203,7 +203,7 @@ impl RequestQueue for UnifiedQueue {
203203
///
204204
/// DEPRECATED: This method is deprecated and should not be used with the new unified queue design.
205205
/// Applications should now create a channel when adding the request and wait on that channel directly.
206-
async fn wait_for_match(&self, request_id: &str, ttl_ms: u64) -> Result<Option<MatchResult>, BumpError> {
206+
async fn wait_for_match(&self, request_id: &str, ttl_ms: u64) -> Result<Option<(MatchResult, MatchResult)>, BumpError> {
207207
log::warn!("wait_for_match() is deprecated and may cause race conditions. Requests should include a channel when created.");
208208

209209
// Create a channel for the match result

src/service.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl MatchingService {
113113
payload: Option<String>,
114114
expires_at: OffsetDateTime,
115115
request_type: RequestType
116-
) -> (QueuedRequest, std::pin::Pin<Box<dyn std::future::Future<Output = Result<MatchResult, Box<dyn std::error::Error>>> + Send>>) {
116+
) -> (QueuedRequest, std::pin::Pin<Box<dyn std::future::Future<Output = Result<(MatchResult, MatchResult), Box<dyn std::error::Error>>> + Send>>) {
117117
match request_type {
118118
RequestType::Bump => {
119119
// For Bump requests, use broadcast channel so both sides can receive
@@ -222,7 +222,7 @@ impl MatchingService {
222222
sender_id: Some(request_id),
223223
receiver_id: Some(our_match_result.matched_with),
224224
timestamp: our_match_result.timestamp,
225-
payload: Some(request.payload),
225+
payload: None, // Send requests don't receive payload
226226
message: None,
227227
});
228228
},
@@ -249,7 +249,7 @@ impl MatchingService {
249249
sender_id: Some(request_id),
250250
receiver_id: Some(our_match_result.matched_with),
251251
timestamp: our_match_result.timestamp,
252-
payload: Some(request.payload),
252+
payload: None, // Send requests don't receive payload
253253
message: None,
254254
});
255255
},
@@ -337,12 +337,22 @@ impl MatchingService {
337337
// We got a match result from the oneshot channel
338338
log::info!("Match found for receive request {}", request_id);
339339

340+
// Destructure the match result tuple
341+
let (send_result, recv_result) = match_result;
342+
343+
// For receive requests, we want the receive side result
344+
let our_match_result = if request_id == send_result.matched_with {
345+
recv_result // We're the receive side
346+
} else {
347+
send_result // We're the send side
348+
};
349+
340350
return Ok(MatchResponse {
341351
status: MatchStatus::Matched,
342-
sender_id: Some(match_result.matched_with),
352+
sender_id: Some(our_match_result.matched_with),
343353
receiver_id: Some(request_id),
344-
timestamp: match_result.timestamp,
345-
payload: match_result.payload,
354+
timestamp: our_match_result.timestamp,
355+
payload: our_match_result.payload,
346356
message: None,
347357
});
348358
},
@@ -417,17 +427,17 @@ impl MatchingService {
417427
// Add the request to the queue
418428
log::info!("Adding bump request {} to queue", request_id);
419429
match self.queue.add_request(queued_request).await {
420-
Ok(Some(match_result)) => {
430+
Ok(Some((send_result, recv_result))) => {
421431
// Immediate match found
422432
log::info!("Immediate match found for bump request {}", request_id);
423433

424434
// Choose the correct match result based on which side we are
425-
let our_match_result = if request_id == send_match_result.matched_with {
435+
let our_match_result = if request_id == send_result.matched_with {
426436
// We are the receive side
427-
recv_match_result
437+
recv_result
428438
} else {
429439
// We are the send side
430-
send_match_result
440+
send_result
431441
};
432442

433443
return Ok(MatchResponse {
@@ -446,17 +456,17 @@ impl MatchingService {
446456
// Wait for a match with timeout
447457
let ttl = std::time::Duration::from_millis(request.ttl as u64);
448458
match tokio::time::timeout(ttl, rx).await {
449-
Ok(Ok(match_result)) => {
459+
Ok(Ok((send_result, recv_result))) => {
450460
// We got a match result from the oneshot channel
451461
log::info!("Match found for bump request {}", request_id);
452462

453463
// Choose the correct match result based on which side we are
454-
let our_match_result = if request_id == send_match_result.matched_with {
464+
let our_match_result = if request_id == send_result.matched_with {
455465
// We are the receive side
456-
recv_match_result
466+
recv_result
457467
} else {
458468
// We are the send side
459-
send_match_result
469+
send_result
460470
};
461471

462472
return Ok(MatchResponse {

0 commit comments

Comments
 (0)