diff --git a/src/asset_bundle/import/ImportABSystem.re b/src/asset_bundle/import/ImportABSystem.re index 230200df16..5799fb5f22 100755 --- a/src/asset_bundle/import/ImportABSystem.re +++ b/src/asset_bundle/import/ImportABSystem.re @@ -18,15 +18,18 @@ module All = { ParseABSystem.WAB.unsafeGetHashId(abRelativePath, wholeManifest); isAssetBundleArrayBufferCachedFunc(. abRelativePath, hashId) + |> Most.fromPromise |> Most.flatMap(isCached => isCached ? - getAssetBundleArrayBufferCacheFunc(. abRelativePath) : + getAssetBundleArrayBufferCacheFunc(. abRelativePath) + |> Most.fromPromise : LoadABSystem.load( getAssetBundlePathFunc(.) ++ abRelativePath, fetchFunc, ) |> Most.flatMap(ab => cacheAssetBundleArrayBufferFunc(. abRelativePath, ab, hashId) + |> Most.fromPromise |> Most.map(() => ab) |> Most.concat(Most.just(ab)) ) @@ -49,6 +52,7 @@ module SAB = { ), ) => initAssetBundleArrayBufferCacheFunc(.) + |> Most.fromPromise |> Most.concat( Most.just(sabRelativePath) |> Most.flatMap(sabRelativePath => { @@ -171,6 +175,7 @@ module RAB = { ParseABSystem.WAB.getWholeDependencyRelationMap(wholeManifest); initAssetBundleArrayBufferCacheFunc(.) + |> Most.fromPromise |> Most.concat( FindDependencyDataSystem.findAllDependencyRAbRelativePathByDepthSearch( abRelativePath, @@ -218,7 +223,8 @@ module RAB = { }; module WAB = { - let loadWABAndSetToState = (wabRelativePath, (getAssetBundlePathFunc, fetchFunc)) => + let loadWABAndSetToState = + (wabRelativePath, (getAssetBundlePathFunc, fetchFunc)) => Most.just(wabRelativePath) |> Most.flatMap(wabRelativePath => { let state = @@ -250,7 +256,7 @@ module WAB = { ) |> StateDataMainService.setState(StateDataMain.stateData) |> ignore; - }) + }); }); }; diff --git a/src/asset_bundle/import/LoadABSystem.re b/src/asset_bundle/import/LoadABSystem.re index a632ab6acb..59298d2644 100755 --- a/src/asset_bundle/import/LoadABSystem.re +++ b/src/asset_bundle/import/LoadABSystem.re @@ -30,10 +30,15 @@ let load = (abPath: string, fetchFunc) => /* TODO need rewrite by editor */ let getAssetBundlePath = (.) => ""; -let initAssetBundleArrayBufferCache = (.) => Most.empty(); +let initAssetBundleArrayBufferCache = + (.) => + Js.Promise.make((~resolve, ~reject) => + (PromiseType.convertResolveToUnit(resolve))(.) + ); let isAssetBundleArrayBufferCached = - (. abRelativePath: string, hashId: string) => Most.just(false); + (. abRelativePath: string, hashId: string) => + Js.Promise.make((~resolve, ~reject) => resolve(. false)); let getAssetBundleArrayBufferCache = (. abRelativePath: string) => @@ -49,4 +54,6 @@ let getAssetBundleArrayBufferCache = let cacheAssetBundleArrayBuffer = (. abRelativePath: string, ab: ArrayBuffer.t, hashId: string) => - Most.empty(); \ No newline at end of file + Js.Promise.make((~resolve, ~reject) => + (PromiseType.convertResolveToUnit(resolve))(.) + ); \ No newline at end of file diff --git a/src/external/PromiseType.re b/src/external/PromiseType.re new file mode 100644 index 0000000000..5b4796411a --- /dev/null +++ b/src/external/PromiseType.re @@ -0,0 +1,2 @@ +external convertResolveToUnit: ((. 'a) => unit) => (. unit) => unit = + "%identity"; \ No newline at end of file diff --git a/test/integration/no_worker/asset_bundle/load/loadRAB_test.re b/test/integration/no_worker/asset_bundle/load/loadRAB_test.re index b8d1400f79..b0f010c2bd 100755 --- a/test/integration/no_worker/asset_bundle/load/loadRAB_test.re +++ b/test/integration/no_worker/asset_bundle/load/loadRAB_test.re @@ -61,10 +61,13 @@ let _ = (.) => { valueRef := 2; - Most.empty(); + Js.Promise.make((~resolve, ~reject) => + (PromiseType.convertResolveToUnit(resolve))(.) + ); }, ~isAssetBundleArrayBufferCachedFunc= - (. _, _) => false |> Most.just, + (. _, _) => + Js.Promise.make((~resolve, ~reject) => resolve(. false)), ~fetchFunc=fetch, (), ) @@ -101,7 +104,8 @@ let _ = ImportABTool.RAB.loadAllDependencyRABAndSetToState( ~abRelativePath=rab3RelativePath, ~isAssetBundleArrayBufferCachedFunc= - (. _, _) => false |> Most.just, + (. _, _) => + Js.Promise.make((~resolve, ~reject) => resolve(. false)), ~fetchFunc=fetch, (), ) @@ -128,9 +132,11 @@ let _ = ImportABTool.RAB.loadAllDependencyRABAndSetToState( ~abRelativePath=rab3RelativePath, ~isAssetBundleArrayBufferCachedFunc= - (. _, _) => true |> Most.just, + (. _, _) => + Js.Promise.make((~resolve, ~reject) => resolve(. true)), ~getAssetBundleArrayBufferCacheFunc= - (. _) => rab1 |> Most.just, + (. _) => + Js.Promise.make((~resolve, ~reject) => resolve(. rab1)), ~fetchFunc=fetch, (), ) @@ -158,13 +164,17 @@ let _ = ~abRelativePath=rab3RelativePath, ~isAssetBundleArrayBufferCachedFunc= (. abRelativePath, hashId) => - ( - JudgeTool.isEqual(abRelativePath, rab1RelativePath) ? - true : false - ) - |> Most.just, + Js.Promise.make((~resolve, ~reject) => + resolve(. + JudgeTool.isEqual(abRelativePath, rab1RelativePath) ? + true : false, + ) + ), ~getAssetBundleArrayBufferCacheFunc= - (. _) => rab1 |> Most.just, + (. _) => + Js.Promise.make((~resolve, ~reject) => + resolve(. rab1) + ), ~fetchFunc=fetch, (), ) @@ -200,20 +210,26 @@ let _ = ~abRelativePath=rab3RelativePath, ~isAssetBundleArrayBufferCachedFunc= (. abRelativePath, hashId) => - ( - JudgeTool.isEqual(abRelativePath, rab1RelativePath) ? - true : false - ) - |> Most.just, + Js.Promise.make((~resolve, ~reject) => + resolve(. + JudgeTool.isEqual(abRelativePath, rab1RelativePath) ? + true : false, + ) + ), ~getAssetBundleArrayBufferCacheFunc= - (. _) => rab1 |> Most.just, + (. _) => + Js.Promise.make((~resolve, ~reject) => + resolve(. rab1) + ), ~cacheAssetBundleArrayBufferFunc= (. abRelativePath, ab, hashId) => { cachedABRelativePathRef := abRelativePath; cachedABHashIdRef := hashId; - Most.empty(); + Js.Promise.make((~resolve, ~reject) => + (PromiseType.convertResolveToUnit(resolve))(.) + ); }, ~fetchFunc=fetch, (), diff --git a/test/integration/no_worker/asset_bundle/load/loadSAB_test.re b/test/integration/no_worker/asset_bundle/load/loadSAB_test.re index c8af87a96c..2c5252583d 100755 --- a/test/integration/no_worker/asset_bundle/load/loadSAB_test.re +++ b/test/integration/no_worker/asset_bundle/load/loadSAB_test.re @@ -97,10 +97,15 @@ let _ = (.) => { valueRef := 2; - Most.empty(); + Js.Promise.make((~resolve, ~reject) => + (PromiseType.convertResolveToUnit(resolve))(.) + ); }, ~isAssetBundleArrayBufferCachedFunc= - (. _, _) => false |> Most.just, + (. _, _) => + Js.Promise.make((~resolve, ~reject) => + resolve(. false) + ), ~fetchFunc=fetch, (), ) @@ -126,9 +131,11 @@ let _ = ImportABTool.SAB.loadSABAndSetToState( ~sabRelativePath=sab1RelativePath, ~isAssetBundleArrayBufferCachedFunc= - (. _, _) => true |> Most.just, + (. _, _) => + Js.Promise.make((~resolve, ~reject) => resolve(. true)), ~getAssetBundleArrayBufferCacheFunc= - (. _) => rab1 |> Most.just, + (. _) => + Js.Promise.make((~resolve, ~reject) => resolve(. rab1)), ~fetchFunc=fetch, (), ) @@ -156,13 +163,17 @@ let _ = ~sabRelativePath=sab1RelativePath, ~isAssetBundleArrayBufferCachedFunc= (. abRelativePath, hashId) => - ( - JudgeTool.isEqual(abRelativePath, rab1RelativePath) ? - true : false - ) - |> Most.just, + Js.Promise.make((~resolve, ~reject) => + resolve(. + JudgeTool.isEqual(abRelativePath, rab1RelativePath) ? + true : false, + ) + ), ~getAssetBundleArrayBufferCacheFunc= - (. _) => rab1 |> Most.just, + (. _) => + Js.Promise.make((~resolve, ~reject) => + resolve(. rab1) + ), ~fetchFunc=fetch, (), ) @@ -194,7 +205,10 @@ let _ = ImportABTool.SAB.loadSABAndSetToState( ~sabRelativePath=sab1RelativePath, ~isAssetBundleArrayBufferCachedFunc= - (. abRelativePath, hashId) => false |> Most.just, + (. abRelativePath, hashId) => + Js.Promise.make((~resolve, ~reject) => + resolve(. false) + ), ~fetchFunc=fetch, (), ) @@ -227,7 +241,10 @@ let _ = ImportABTool.SAB.loadSABAndSetToState( ~sabRelativePath=sab1RelativePath, ~isAssetBundleArrayBufferCachedFunc= - (. abRelativePath, hashId) => false |> Most.just, + (. abRelativePath, hashId) => + Js.Promise.make((~resolve, ~reject) => + resolve(. false) + ), ~fetchFunc=fetch, (), ) diff --git a/test/unit/asset_bundle/LoadABSystem_test.re b/test/unit/asset_bundle/LoadABSystem_test.re index e478dd4f15..0404b76cf2 100755 --- a/test/unit/asset_bundle/LoadABSystem_test.re +++ b/test/unit/asset_bundle/LoadABSystem_test.re @@ -20,7 +20,7 @@ let _ = describe("isAssetBundleArrayBufferCached", () => testPromise("return false", () => LoadABSystem.isAssetBundleArrayBufferCached(. "", "") - |> MostTool.testStream(result => result |> expect == false |> resolve) + |> then_(result => result |> expect == false |> resolve) ) ); @@ -38,7 +38,7 @@ let _ = let ab = Obj.magic(-1); LoadABSystem.cacheAssetBundleArrayBuffer(. "", ab, "") - |> MostTool.testStream(() => 1 |> expect == 1 |> resolve); + |> then_(_ => 1 |> expect == 1 |> resolve); }) ); }); \ No newline at end of file