core API: move now_ms to spirc.rs

This commit is contained in:
awiouy 2018-02-10 11:01:19 +01:00
parent 55f27a9e0a
commit 77882836ce
2 changed files with 10 additions and 10 deletions

View file

@ -8,7 +8,6 @@ use std::ops::{Mul, Rem, Shr};
use std::fs;
use std::path::Path;
use std::process::Command;
use std::time::{UNIX_EPOCH, SystemTime};
mod int128;
mod spotify_id;
@ -22,14 +21,6 @@ pub fn rand_vec<G: Rng, R: Rand>(rng: &mut G, size: usize) -> Vec<R> {
rng.gen_iter().take(size).collect()
}
pub fn now_ms() -> i64 {
let dur = match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(dur) => dur,
Err(err) => err.duration(),
};
(dur.as_secs() * 1000 + (dur.subsec_nanos() / 1000_000) as u64) as i64
}
pub fn mkdir_existing(path: &Path) -> io::Result<()> {
fs::create_dir(path).or_else(|err| {
if err.kind() == io::ErrorKind::AlreadyExists {

View file

@ -6,7 +6,7 @@ use protobuf::{self, Message};
use core::config::ConnectConfig;
use core::mercury::MercuryError;
use core::session::Session;
use core::util::{now_ms, SpotifyId, SeqGenerator};
use core::util::{SpotifyId, SeqGenerator};
use core::version;
use protocol;
@ -18,6 +18,7 @@ use playback::player::Player;
use std;
use rand;
use rand::Rng;
use std::time::{UNIX_EPOCH, SystemTime};
pub struct SpircTask {
player: Player,
@ -53,6 +54,14 @@ pub struct Spirc {
commands: mpsc::UnboundedSender<SpircCommand>,
}
fn now_ms() -> i64 {
let dur = match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(dur) => dur,
Err(err) => err.duration(),
};
(dur.as_secs() * 1000 + (dur.subsec_nanos() / 1000_000) as u64) as i64
}
fn initial_state() -> State {
protobuf_init!(protocol::spirc::State::new(), {
repeat: false,