DellCliff opened a new issue #115:
URL: https://github.com/apache/incubator-annotator/issues/115


   What is the reason behind matchers producing AsyncGenerators. They don't do 
IO or wait on callbacks as far as I can see. Having an async function which 
doesn't need to be one has serious disadvantages, like async-infection up the 
call-chain, race conditions and so on.
   
   A simple modification of `packages/selector/src/text/match-text-position.ts` 
removes the unnecessary async.
   
   ```
   export function textPositionSelectorMatcher(
     selector: TextPositionSelector,
   ): <TChunk extends Chunk<any>>(
     scope: Chunker<TChunk>,
   ) => AsyncGenerator<ChunkRange<TChunk>, void, void> {
     const { start, end } = selector;
   
     return async function* matchAll<TChunk extends Chunk<string>>(
       textChunks: Chunker<TChunk>,
     ) {
       const codeUnitSeeker = new TextSeeker(textChunks);
       const codePointSeeker = new CodePointSeeker(codeUnitSeeker);
   
       codePointSeeker.seekTo(start);
       const startChunk = codeUnitSeeker.currentChunk;
       const startIndex = codeUnitSeeker.offsetInChunk;
       codePointSeeker.seekTo(end);
       const endChunk = codeUnitSeeker.currentChunk;
       const endIndex = codeUnitSeeker.offsetInChunk;
   
       yield { startChunk, startIndex, endChunk, endIndex };
     };
   }
   ```
   
   ```
   export function textPositionSelectorMatcher(
     selector: TextPositionSelector,
   ): <TChunk extends Chunk<any>>(
     scope: Chunker<TChunk>,
   ) => Generator<ChunkRange<TChunk>, void, void> {
     const { start, end } = selector;
   
     return function* matchAll<TChunk extends Chunk<string>>(
       textChunks: Chunker<TChunk>,
     ) {
       const codeUnitSeeker = new TextSeeker(textChunks);
       const codePointSeeker = new CodePointSeeker(codeUnitSeeker);
   
       codePointSeeker.seekTo(start);
       const startChunk = codeUnitSeeker.currentChunk;
       const startIndex = codeUnitSeeker.offsetInChunk;
       codePointSeeker.seekTo(end);
       const endChunk = codeUnitSeeker.currentChunk;
       const endIndex = codeUnitSeeker.offsetInChunk;
   
       yield { startChunk, startIndex, endChunk, endIndex };
     };
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@annotator.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to