0

Is there a way to asynchronously use _.some()? I've got the below code snippet that I'm trying to switch to an asynchronous method to prevent it from causing timeout issues.

DLClear = function( obj, squarePt ) {

    var wallPaths = findObjs( {
         _type  : 'path',
         _pageid: obj.get('pageid'),
        layer   : 'walls'
    } );

    var landingPt    = [ obj.get('left'), obj.get('top'), 1 ];
    var wallSegments = PathMath.toSegments( wallPaths );
    var squareSeg    = [ landingPt, squarePt ];

    var blocked = _.some( wallSegments, function( wallSeg ) {
        return PathMath.segmentIntersection( squareSeg, wallSeg );
    } );
    return !blocked;
},

The platform I'm writing for is using javascript ES7 so async/await is usable.

Any and all help is appreciated,

Scott

Dai
  • 141,631
  • 28
  • 261
  • 374
Scott Casey
  • 113
  • 7
  • 1
    Asynchronous code won't help you here because your `DLClear` function (and `_.some`) are not IO-bound, but a "busy" function. If your code is taking too long to execute in your environment it suggests you're using an inefficient algorithm. What does your `segmentIntersection` function do? How big is the `wallSegments` array? – Dai Apr 08 '17 at 03:28
  • This is for a script for a virtual table top (VTT) gaming platform. segmentIntersection determines if the segments passed to it intersect at any point. The size of the wallSegments array is not fixed. It depends on how many wall segments the user has created on the VTT, so could be 1 entry or could be a couple hundred or thous and (ok thousand's probably hyperbole). I know that _.some() is not what I'll wind up using, but is there a way I could switch it to using something like _.defer() to wait fro the call stack to finish before running? – Scott Casey Apr 08 '17 at 03:42

1 Answers1

0

You can use the async library that designed for use with Node.js and for this case .each function will help you.

Majid Parvin
  • 4,499
  • 5
  • 29
  • 47