Skip to content

Commit

Permalink
couple renames and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
podusowski committed Oct 25, 2023
1 parent bcef7b5 commit 39c0fbb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions walkers/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use egui::Context;
use futures::StreamExt;
use reqwest::header::USER_AGENT;

use crate::{tiles::Tile, mercator::TileId, providers::TileSource};
use crate::{mercator::TileId, providers::TileSource, tiles::Tile};

#[derive(Debug, thiserror::Error)]
enum Error {
Expand All @@ -13,7 +13,8 @@ enum Error {
Image(String),
}

async fn download_single(client: &reqwest::Client, url: &str) -> Result<Tile, Error> {
/// Download and decode the tile.
async fn download_and_decode(client: &reqwest::Client, url: &str) -> Result<Tile, Error> {
let image = client
.get(url)
.header(USER_AGENT, "Walkers")
Expand All @@ -33,7 +34,7 @@ async fn download_single(client: &reqwest::Client, url: &str) -> Result<Tile, Er
Tile::from_image_bytes(&image).map_err(Error::Image)
}

async fn download<S>(
async fn download_continuously_impl<S>(
source: S,
mut request_rx: futures::channel::mpsc::Receiver<TileId>,
mut tile_tx: futures::channel::mpsc::Sender<(TileId, Tile)>,
Expand All @@ -51,7 +52,7 @@ where

log::debug!("Getting {:?} from {}.", request, url);

match download_single(&client, &url).await {
match download_and_decode(&client, &url).await {
Ok(tile) => {
tile_tx.try_send((request, tile)).map_err(|_| ())?;
egui_ctx.request_repaint();
Expand All @@ -63,15 +64,16 @@ where
}
}

pub async fn download_wrap<S>(
/// Continuously download tiles requested via request channel.
pub async fn download_continuously<S>(
source: S,
request_rx: futures::channel::mpsc::Receiver<TileId>,
tile_tx: futures::channel::mpsc::Sender<(TileId, Tile)>,
egui_ctx: Context,
) where
S: TileSource + Send + 'static,
{
if download(source, request_rx, tile_tx, egui_ctx)
if download_continuously_impl(source, request_rx, tile_tx, egui_ctx)
.await
.is_err()
{
Expand Down
4 changes: 2 additions & 2 deletions walkers/src/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{collections::HashMap, sync::Arc};
use egui::{pos2, Color32, Context, Mesh, Rect, Vec2};
use egui_extras::RetainedImage;

use crate::download::download_wrap;
use crate::download::download_continuously;
use crate::io::Runtime;
use crate::mercator::TileId;
use crate::providers::{Attribution, TileSource};
Expand Down Expand Up @@ -67,7 +67,7 @@ impl Tiles {
let (request_tx, request_rx) = futures::channel::mpsc::channel(channel_size);
let (tile_tx, tile_rx) = futures::channel::mpsc::channel(channel_size);
let attribution = source.attribution();
let runtime = Runtime::new(download_wrap(source, request_rx, tile_tx, egui_ctx));
let runtime = Runtime::new(download_continuously(source, request_rx, tile_tx, egui_ctx));

Self {
attribution,
Expand Down

0 comments on commit 39c0fbb

Please sign in to comment.