This repository has been archived by the owner on Oct 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add wasm32-unknown-unknown support to runtime-native (#22)
* update versions Signed-off-by: Yoshua Wuyts <[email protected]> * runtime 0.3.0-alpha.3 Signed-off-by: Yoshua Wuyts <[email protected]> * add wasm32-unknown-unknown support Signed-off-by: Yoshua Wuyts <[email protected]> * reorder cfgs Signed-off-by: Yoshua Wuyts <[email protected]> * Update runtime-native/src/wasm32.rs Co-Authored-By: yoshuawuyts <[email protected]> * wasm-bindgen feature flag Signed-off-by: Yoshua Wuyts <[email protected]> * remove unneeded combinators Signed-off-by: Yoshua Wuyts <[email protected]>
- Loading branch information
1 parent
86aad62
commit 95414d6
Showing
6 changed files
with
124 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use futures::prelude::*; | ||
use futures::{future::BoxFuture, task::SpawnError}; | ||
use lazy_static::lazy_static; | ||
|
||
use std::io; | ||
use std::net::SocketAddr; | ||
use std::pin::Pin; | ||
|
||
mod tcp; | ||
mod udp; | ||
|
||
use tcp::{TcpListener, TcpStream}; | ||
use udp::UdpSocket; | ||
|
||
lazy_static! { | ||
static ref JULIEX_THREADPOOL: juliex::ThreadPool = { | ||
juliex::ThreadPool::with_setup(|| { | ||
runtime_raw::set_runtime(&Native); | ||
}) | ||
}; | ||
} | ||
|
||
/// The Native runtime. | ||
#[derive(Debug)] | ||
pub struct Native; | ||
|
||
impl runtime_raw::Runtime for Native { | ||
fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> { | ||
JULIEX_THREADPOOL.spawn_boxed(fut.into()); | ||
Ok(()) | ||
} | ||
|
||
fn connect_tcp_stream( | ||
&self, | ||
addr: &SocketAddr, | ||
) -> BoxFuture<'static, io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>> { | ||
let romio_connect = romio::TcpStream::connect(addr); | ||
let connect = romio_connect.map(|res| { | ||
res.map(|romio_stream| { | ||
Box::pin(TcpStream { romio_stream }) as Pin<Box<dyn runtime_raw::TcpStream>> | ||
}) | ||
}); | ||
connect.boxed() | ||
} | ||
|
||
fn bind_tcp_listener( | ||
&self, | ||
addr: &SocketAddr, | ||
) -> io::Result<Pin<Box<dyn runtime_raw::TcpListener>>> { | ||
let romio_listener = romio::TcpListener::bind(&addr)?; | ||
Ok(Box::pin(TcpListener { romio_listener })) | ||
} | ||
|
||
fn bind_udp_socket( | ||
&self, | ||
addr: &SocketAddr, | ||
) -> io::Result<Pin<Box<dyn runtime_raw::UdpSocket>>> { | ||
let romio_socket = romio::UdpSocket::bind(&addr)?; | ||
Ok(Box::pin(UdpSocket { romio_socket })) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use futures::prelude::*; | ||
use futures::{future::BoxFuture, task::SpawnError}; | ||
// use futures::compat::*; | ||
|
||
use std::io; | ||
use std::net::SocketAddr; | ||
use std::pin::Pin; | ||
|
||
use wasm_bindgen::prelude::*; | ||
use wasm_bindgen_futures::future_to_promise; | ||
|
||
/// The Native runtime. | ||
#[derive(Debug)] | ||
pub struct Native; | ||
|
||
impl runtime_raw::Runtime for Native { | ||
fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> { | ||
use futures01::future::Future; | ||
let fut = fut.unit_error().compat(); | ||
wasm_bindgen_futures::spawn_local(fut); | ||
Ok(()) | ||
} | ||
|
||
fn connect_tcp_stream( | ||
&self, | ||
_addr: &SocketAddr, | ||
) -> BoxFuture<'static, io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>> { | ||
panic!("Connecting TCP streams is currently not supported in wasm"); | ||
} | ||
|
||
fn bind_tcp_listener( | ||
&self, | ||
_addr: &SocketAddr, | ||
) -> io::Result<Pin<Box<dyn runtime_raw::TcpListener>>> { | ||
panic!("Binding TCP listeners is currently not supported in wasm"); | ||
} | ||
|
||
fn bind_udp_socket( | ||
&self, | ||
_addr: &SocketAddr, | ||
) -> io::Result<Pin<Box<dyn runtime_raw::UdpSocket>>> { | ||
panic!("Binding UDP sockets is currently not supported in wasm"); | ||
} | ||
} |