Shorten `Pin<Box<dyn Future<Output=Result<T,E>> + 'static>>` into `OwnedFuture<T,E>`.
This is technically stricter on `fetch` impls, but right now we can't support non-`'static` futures at all.
This commit is contained in:
parent
aab339880d
commit
33d26b9149
|
@ -283,11 +283,7 @@ impl NavigatorBackend for NullNavigatorBackend {
|
|||
) {
|
||||
}
|
||||
|
||||
fn fetch(
|
||||
&self,
|
||||
url: String,
|
||||
_opts: RequestOptions,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>>>> {
|
||||
fn fetch(&self, url: String, _opts: RequestOptions) -> OwnedFuture<Vec<u8>, Error> {
|
||||
let mut path = self.relative_base_path.clone();
|
||||
path.push(url);
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! Management of async loaders
|
||||
|
||||
use crate::avm1::{Object, TObject, Value};
|
||||
use crate::backend::navigator::OwnedFuture;
|
||||
use crate::context::{ActionQueue, ActionType};
|
||||
use crate::display_object::{DisplayObject, MorphShape, TDisplayObject};
|
||||
use crate::player::{Player, NEWEST_PLAYER_VERSION};
|
||||
|
@ -8,8 +9,6 @@ use crate::tag_utils::SwfMovie;
|
|||
use crate::xml::XMLNode;
|
||||
use gc_arena::{Collect, CollectionContext};
|
||||
use generational_arena::{Arena, Index};
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::{Arc, Mutex, Weak};
|
||||
use url::form_urlencoded;
|
||||
|
||||
|
@ -67,9 +66,9 @@ impl<'gc> LoadManager<'gc> {
|
|||
&mut self,
|
||||
player: Weak<Mutex<Player>>,
|
||||
target_clip: DisplayObject<'gc>,
|
||||
fetch: Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>>>>,
|
||||
fetch: OwnedFuture<Vec<u8>, Error>,
|
||||
target_broadcaster: Option<Object<'gc>>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static>> {
|
||||
) -> OwnedFuture<(), Error> {
|
||||
let loader = Loader::Movie {
|
||||
self_handle: None,
|
||||
target_clip,
|
||||
|
@ -113,8 +112,8 @@ impl<'gc> LoadManager<'gc> {
|
|||
&mut self,
|
||||
player: Weak<Mutex<Player>>,
|
||||
target_object: Object<'gc>,
|
||||
fetch: Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>>>>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static>> {
|
||||
fetch: OwnedFuture<Vec<u8>, Error>,
|
||||
) -> OwnedFuture<(), Error> {
|
||||
let loader = Loader::Form {
|
||||
self_handle: None,
|
||||
target_object,
|
||||
|
@ -135,8 +134,8 @@ impl<'gc> LoadManager<'gc> {
|
|||
player: Weak<Mutex<Player>>,
|
||||
target_node: XMLNode<'gc>,
|
||||
active_clip: DisplayObject<'gc>,
|
||||
fetch: Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>>>>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static>> {
|
||||
fetch: OwnedFuture<Vec<u8>, Error>,
|
||||
) -> OwnedFuture<(), Error> {
|
||||
let loader = Loader::XML {
|
||||
self_handle: None,
|
||||
active_clip,
|
||||
|
@ -239,8 +238,8 @@ impl<'gc> Loader<'gc> {
|
|||
pub fn movie_loader(
|
||||
&mut self,
|
||||
player: Weak<Mutex<Player>>,
|
||||
fetch: Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>>>>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static>> {
|
||||
fetch: OwnedFuture<Vec<u8>, Error>,
|
||||
) -> OwnedFuture<(), Error> {
|
||||
let handle = match self {
|
||||
Loader::Movie { self_handle, .. } => self_handle.expect("Loader not self-introduced"),
|
||||
_ => return Box::pin(async { Err("Non-movie loader spawned as movie loader".into()) }),
|
||||
|
@ -394,8 +393,8 @@ impl<'gc> Loader<'gc> {
|
|||
pub fn form_loader(
|
||||
&mut self,
|
||||
player: Weak<Mutex<Player>>,
|
||||
fetch: Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>>>>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static>> {
|
||||
fetch: OwnedFuture<Vec<u8>, Error>,
|
||||
) -> OwnedFuture<(), Error> {
|
||||
let handle = match self {
|
||||
Loader::Form { self_handle, .. } => self_handle.expect("Loader not self-introduced"),
|
||||
_ => return Box::pin(async { Err("Non-form loader spawned as form loader".into()) }),
|
||||
|
@ -472,8 +471,8 @@ impl<'gc> Loader<'gc> {
|
|||
pub fn xml_loader(
|
||||
&mut self,
|
||||
player: Weak<Mutex<Player>>,
|
||||
fetch: Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>>>>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static>> {
|
||||
fetch: OwnedFuture<Vec<u8>, Error>,
|
||||
) -> OwnedFuture<(), Error> {
|
||||
let handle = match self {
|
||||
Loader::XML { self_handle, .. } => self_handle.expect("Loader not self-introduced"),
|
||||
_ => return Box::pin(async { Err("Non-XML loader spawned as XML loader".into()) }),
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! Navigator backend for web
|
||||
|
||||
use log;
|
||||
use ruffle_core::backend::navigator::{Error, NavigationMethod, NavigatorBackend, RequestOptions};
|
||||
use ruffle_core::backend::navigator::{
|
||||
Error, NavigationMethod, NavigatorBackend, OwnedFuture, RequestOptions,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use url::Url;
|
||||
use webbrowser;
|
||||
|
||||
|
@ -63,18 +63,11 @@ impl NavigatorBackend for ExternalNavigatorBackend {
|
|||
};
|
||||
}
|
||||
|
||||
fn fetch(
|
||||
&self,
|
||||
_url: String,
|
||||
_options: RequestOptions,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>>>> {
|
||||
fn fetch(&self, _url: String, _options: RequestOptions) -> OwnedFuture<Vec<u8>, Error> {
|
||||
Box::pin(async { Err("Fetch not implemented on desktop!".into()) })
|
||||
}
|
||||
|
||||
fn spawn_future(
|
||||
&mut self,
|
||||
_future: Pin<Box<dyn Future<Output = Result<(), Error>> + 'static>>,
|
||||
) {
|
||||
fn spawn_future(&mut self, _future: OwnedFuture<(), Error>) {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! Navigator backend for web
|
||||
|
||||
use js_sys::{Array, ArrayBuffer, Uint8Array};
|
||||
use ruffle_core::backend::navigator::{Error, NavigationMethod, NavigatorBackend, RequestOptions};
|
||||
use ruffle_core::backend::navigator::{
|
||||
Error, NavigationMethod, NavigatorBackend, OwnedFuture, RequestOptions,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen_futures::{spawn_local, JsFuture};
|
||||
use web_sys::{window, Blob, BlobPropertyBag, Request, RequestInit, Response};
|
||||
|
@ -77,11 +77,7 @@ impl NavigatorBackend for WebNavigatorBackend {
|
|||
}
|
||||
}
|
||||
|
||||
fn fetch(
|
||||
&self,
|
||||
url: String,
|
||||
options: RequestOptions,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>>>> {
|
||||
fn fetch(&self, url: String, options: RequestOptions) -> OwnedFuture<Vec<u8>, Error> {
|
||||
Box::pin(async move {
|
||||
let mut init = RequestInit::new();
|
||||
|
||||
|
@ -135,7 +131,7 @@ impl NavigatorBackend for WebNavigatorBackend {
|
|||
})
|
||||
}
|
||||
|
||||
fn spawn_future(&mut self, future: Pin<Box<dyn Future<Output = Result<(), Error>> + 'static>>) {
|
||||
fn spawn_future(&mut self, future: OwnedFuture<(), Error>) {
|
||||
spawn_local(async move {
|
||||
if let Err(e) = future.await {
|
||||
log::error!("Asynchronous error occured: {}", e);
|
||||
|
|
Loading…
Reference in New Issue