33import { IndexInterface , DocumentInterface } from "./type.js" ;
44import { create_object , is_string } from "./common.js" ;
55
6- async function lazyExport ( callback , self , key , index_doc , index , data ) {
7- // Run the callback on the given data
8- const res = callback ( key , JSON . stringify ( data ) ) ;
9- // If the callback gives a promise, then wait on that
10- if ( res && res [ "then" ] ) { await res ; }
11-
12- // Recurse to export the next property
13- return await self . export ( callback , self , key , index_doc , index + 1 ) ;
6+ function async ( callback , self , key , index_doc , index , data ) {
7+
8+ setTimeout ( function ( ) {
9+
10+ const res = callback ( key , JSON . stringify ( data ) ) ;
11+
12+ // await isn't supported by ES5
13+
14+ if ( res && res [ "then" ] ) {
15+
16+ res [ "then" ] ( function ( ) {
17+
18+ self . export ( callback , self , key , index_doc , index + 1 ) ;
19+ } )
20+ }
21+ else {
22+
23+ self . export ( callback , self , key , index_doc , index + 1 ) ;
24+ }
25+ } ) ;
1426}
1527
1628/**
1729 * @this IndexInterface
1830 */
1931
20- export async function exportIndex ( callback , self , field , index_doc , index ) {
32+ export function exportIndex ( callback , self , field , index_doc , index ) {
2133
2234 let key , data ;
2335
@@ -69,12 +81,12 @@ export async function exportIndex(callback, self, field, index_doc, index){
6981
7082 default :
7183
72- // If there are no properties remaining to export, then return an empty promise with
73- // 'true'
74- return true ;
84+ return ;
7585 }
7686
77- return await lazyExport ( callback , self || this , field ? field + "." + key : key , index_doc , index , data ) ;
87+ async ( callback , self || this , field ? field + "." + key : key , index_doc , index , data ) ;
88+
89+ return true ;
7890}
7991
8092/**
@@ -124,7 +136,7 @@ export function importIndex(key, data){
124136 * @this DocumentInterface
125137 */
126138
127- export async function exportDocument ( callback , self , field , index_doc , index ) {
139+ export function exportDocument ( callback , self , field , index_doc , index ) {
128140
129141 index || ( index = 0 ) ;
130142 index_doc || ( index_doc = 0 ) ;
@@ -136,16 +148,16 @@ export async function exportDocument(callback, self, field, index_doc, index){
136148
137149 self = this ;
138150
151+ setTimeout ( function ( ) {
139152
140- if ( ! ( await idx . export ( callback , self , index ? field /*.replace(":", "-")*/ : "" , index_doc , index ++ ) ) ) {
141-
142- index_doc ++ ;
143- index = 1 ;
153+ if ( ! idx . export ( callback , self , index ? field /*.replace(":", "-")*/ : "" , index_doc , index ++ ) ) {
144154
145- await self . export ( callback , self , field , index_doc , index ) ;
146- }
155+ index_doc ++ ;
156+ index = 1 ;
147157
148- return true ;
158+ self . export ( callback , self , field , index_doc , index ) ;
159+ }
160+ } ) ;
149161 }
150162 else {
151163
@@ -173,10 +185,10 @@ export async function exportDocument(callback, self, field, index_doc, index){
173185
174186 default :
175187
176- return true ;
188+ return ;
177189 }
178190
179- return await lazyExport ( callback , this , key , index_doc , index , data ) ;
191+ async ( callback , this , key , index_doc , index , data ) ;
180192 }
181193}
182194
0 commit comments