pub(crate) fn ipfs_map(
        &self,
        module: &WasmiModule,
        link: String,
        callback: &str,
        user_data: store::Value,
        flags: Vec<String>,
    ) -> Result<Vec<BlockState>, HostExportError<impl ExportError>> {
        const JSON_FLAG: &str = "json";
        if !flags.contains(&JSON_FLAG.to_string()) {
            return Err(HostExportError(format!("Flags must contain 'json'")));
        }

        let host_metrics = module.host_metrics.clone();
        let valid_module = module.valid_module.clone();
        let ctx = module.ctx.clone();
        let callback = callback.to_owned();
        // Create a base error message to avoid borrowing headaches
        let errmsg = format!(
            "ipfs_map: callback '{}' failed when processing file '{}'",
            &*callback, &link
        );

        let start = Instant::now();
        let mut last_log = Instant::now();
        let logger = ctx.logger.new(o!("ipfs_map" => link.clone()));
        block_on(
            self.link_resolver
                .json_stream(&Link { link })
                .and_then(move |stream| {
                    stream
                        .and_then(move |sv| {
                            let module = WasmiModule::from_valid_module_with_ctx(
                                valid_module.clone(),
                                ctx.clone(),
                                host_metrics.clone(),
                            )?;
                            let result =
                                module.handle_json_callback(&*callback, &sv.value, &user_data);
                            // Log progress every 15s
                            if last_log.elapsed() > Duration::from_secs(15) {
                                debug!(
                                    logger,
                                    "Processed {} lines in {}s so far",
                                    sv.line,
                                    start.elapsed().as_secs()
                                );
                                last_log = Instant::now();
                            }
                            result
                        })
                        .collect()
                })
                .map_err(move |e| HostExportError(format!("{}: {}", errmsg, e.to_string()))),
        )
    }
// Read the IPFS file `link`, split it into JSON objects, and invoke the
// exported function `callback` on each JSON object. The successful return
// value contains the block state produced by each callback invocation. Each
// invocation of `callback` happens in its own instance of a WASM module,
// which is identical to `module` when it was first started. The signature
// of the callback must be `callback(JSONValue, Value)`, and the `userData`
// parameter is passed to the callback without any changes
Read the IPFS file `link`, split it into JSON objects, and invoke the
exported function `callback` on each JSON object. The successful return
value contains the block state produced by each callback invocation. Each
invocation of `callback` happens in its own instance of a WASM module,
which is identical to `module` when it was first started. The signature
of the callback must be `callback(JSONValue, Value)`, and the `userData`
parameter is passed to the callback without any changes
Read the IPFS file ` link ` split it into JSON objects and invoke the exported function ` callback ` on each JSON object . The successful return value contains the block state produced by each callback invocation . Each invocation of ` callback ` happens in its own instance of a WASM module which is identical to ` module ` when it was first started . The signature of the callback must be ` callback ( JSONValue Value ) ` and the ` userData ` parameter is passed to the callback without any changes
pub(crate) fn ipfs_map(
        &self,
        module: &WasmiModule,
        link: String,
        callback: &str,
        user_data: store::Value,
        flags: Vec<String>,
    ) -> Result<Vec<BlockState>, HostExportError<impl ExportError>> {
        const JSON_FLAG: &str = "json";
        if !flags.contains(&JSON_FLAG.to_string()) {
            return Err(HostExportError(format!("Flags must contain 'json'")));
        }
        let host_metrics = module.host_metrics.clone();
        let valid_module = module.valid_module.clone();
        let ctx = module.ctx.clone();
        let callback = callback.to_owned();
        // Create a base error message to avoid borrowing headaches
        let errmsg = format!(
            "ipfs_map: callback '{}' failed when processing file '{}'",
            &*callback, &link
        );
        let start = Instant::now();
        let mut last_log = Instant::now();
        let logger = ctx.logger.new(o!("ipfs_map" => link.clone()));
        block_on(
            self.link_resolver
                .json_stream(&Link { link })
                .and_then(move |stream| {
                    stream
                        .and_then(move |sv| {
                            let module = WasmiModule::from_valid_module_with_ctx(
                                valid_module.clone(),
                                ctx.clone(),
                                host_metrics.clone(),
                            )?;
                            let result =
                                module.handle_json_callback(&*callback, &sv.value, &user_data);
                            // Log progress every 15s
                            if last_log.elapsed() > Duration::from_secs(15) {
                                debug!(
                                    logger,
                                    "Processed {} lines in {}s so far",
                                    sv.line,
                                    start.elapsed().as_secs()
                                );
                                last_log = Instant::now();
                            }
                            result
                        })
                        .collect()
                })
                .map_err(move |e| HostExportError(format!("{}: {}", errmsg, e.to_string()))),
        )
    }
pub ( crate ) fn ipfs_map ( & self , module : & WasmiModule , link : String , callback : & str , user_data : store :: Value , flags : Vec < String > , ) -> Result < Vec < BlockState > , HostExportError < impl ExportError > > { const JSON_FLAG : & str = " " ; if ! flags . contains ( & JSON_FLAG . to_string ( ) ) { return Err ( HostExportError ( format ! ( " " ) ) ) ; } let host_metrics = module . host_metrics . clone ( ) ; let valid_module = module . valid_module . clone ( ) ; let ctx = module . ctx . clone ( ) ; let callback = callback . to_owned ( ) ; // Create a base error message to avoid borrowing headaches let errmsg = format ! ( " " callback link ) ; let start = Instant :: now ( ) ; let mut last_log = Instant :: now ( ) ; let logger = ctx . logger . new ( o ! ( " " link clone ( ) ) ) ; block_on ( self . link_resolver . json_stream ( & Link { link } ) . and_then ( move | stream | { stream . and_then ( move | sv | { let module = WasmiModule :: from_valid_module_with_ctx ( valid_module . clone ( ) , ctx . clone ( ) , host_metrics . clone ( ) , ) ? ; let result = module . handle_json_callback ( & * callback , & sv . value , & user_data ) ; // Log progress every 15s if last_log . elapsed ( ) > Duration :: from_secs ( 15 ) { debug ! ( logger " " sv line start elapsed ( ) as_secs ( ) ) ; last_log = Instant :: now ( ) ; } result } ) . collect ( ) } ) . map_err ( move | e | HostExportError ( format ! ( " " errmsg e to_string ( ) ) ) ) , ) }
Read the IPFS file `link`, split it into JSON objects, and invoke the
exported function `callback` on each JSON object.
Read the IPFS file ` link ` split it into JSON objects and invoke the exported function ` callback ` on each JSON object .
&self
module
&WasmiModule
link
String
callback
&str
user_data
store::Value
flags
Vec<String>
&self
module
&WasmiModule
link
String
callback
&str
user_data
store::Value
flags
Vec<String>