Web Worker not returning result of performing operation

382 views Asked by At

I have a web worker that is not returning the result of performing a computation,the method looks like this:

 self.checkIntersectionForLayerWith = function checkIntersectionForLayerWith(data) {

var checkIntersectionForLayer = function checkIntersectionForLayer() {

    var checkEachConflict = function checkEachConflict(feature){

        var conflict = turf.intersect(feature,data.rectFeature);

            if(conflict != null) {
                _.extend(conflict.properties,feature.properties);
                conflict.id = feature.id;
            }

            return conflict;
        };

    var intersectiontest = self._(data.features)
                                .map(checkEachConflict)
                                .pull(void 0)
                                .thru(self.turf.featurecollection)
                                .value();

    return {
            layerLabel:data.layerLabel,
            query:data.rectFeature,
            result:data.intersectiontest
        };


};

return checkIntersectionForLayer;
}; 

I invoke the method like this:

    self.startQuery = function startQuery(data) {

    if(data != null) {
        var checkIntersectionForLayer = self.checkIntersectionForLayerWith(data);
        var result = checkIntersectionForLayer();
        var payload = {
                type:'rectangle_query_worker_result',
                result:result
        };
        self.postMessage(payload);
    }
};

self.onmessage = function startQueryWorker(e) {
    if(e.data.type === 'start') {
        console.log("Inside the web worker,",e,e.data,e.data.payload);
        self.startQuery(e.data.payload);
    }
    else if(e.data.type === 'setup') { 
        self.setup();
    }
};

I call the nessecary libraries like this:

self.setup = function setup() {

    importScripts('/MapErpMobileDev/leaflet/mobile/js/lib/turf.js');
    importScripts('/MapErpMobileDev/leaflet/mobile/js/lib/lodash.compat.min.js');
};
0

There are 0 answers