0

I have a requirement for my RXJS stream to process chunks of data in 250 millisecond intervals when the page is not visible. Chrome is throttling these intervals to 1000 millisecond intervals. To get around this I have implemented a AsyncAction that uses setInterval within a web worker. I am using it as follows:

export const customScheduler = new AsyncScheduler(WebWorkerAsyncAction)

However, this has not been without problems. When compiling this using JIT it works fine. When compiling it with AOT (another project requirement) It works for the first compilation however every second compilation there after fails with the following error:

ERROR in : Error: Could not resolve ./ from /node_modules/rxjs/internal/scheduler/AsyncScheduler.d.ts at TsCompilerAotCompilerTypeCheckHostAdapter.fromSummaryFileName (\node_modules@angular\compiler-cli\src\transformers\compiler_host.js:272:23) at AotSummaryResolver.fromSummaryFileName (\node_modules@angular\compiler\bundles\compiler.umd.js:26320:30) at \node_modules@angular\compiler\bundles\compiler.umd.js:24481:126 at Array.map () at FromJsonDeserializer.deserialize (\node_modules@angular\compiler\bundles\compiler.umd.js:24481:41) at deserializeSummaries (\node_modules@angular\compiler\bundles\compiler.umd.js:24086:29) at AotSummaryResolver._loadSummaryFile (\node_modules@angular\compiler\bundles\compiler.umd.js:26370:26) at AotSummaryResolver.resolveSummary (\node_modules@angular\compiler\bundles\compiler.umd.js:26328:22) at ToJsonSerializer.loadSummary (\node_modules@angular\compiler\bundles\compiler.umd.js:24310:48) at ToJsonSerializer.visitStaticSymbol (\node_modules@angular\compiler\bundles\compiler.umd.js:24285:32) at ToJsonSerializer.visitOther (\node_modules@angular\compiler\bundles\compiler.umd.js:24250:34) at visitValue (\node_modules@angular\compiler\bundles\compiler.umd.js:2438:24) at \node_modules@angular\compiler\bundles\compiler.umd.js:2451:54 at Array.map () at ToJsonSerializer.ValueTransformer.visitArray (\node_modules@angular\compiler\bundles\compiler.umd.js:2451:24) at visitValue (\node_modules@angular\compiler\bundles\compiler.umd.js:2429:28)

I assume that this is a quirk of using 'internal' RXJS packages but I can't see a way round this without relying on AsyncHandler.

colin-bilkins
  • 291
  • 1
  • 3
  • 9

2 Answers2

1

You could try something like:

import {asyncScheduler} from 'rxjs';

export const customScheduler = new asyncScheduler.constructor(WebWorkerAsyncAction);

This way you don't need to import internal stuff, but still, the constructor contract could always change. Not sure if typescript knows the signature in this case to warn you.

Andrei Tătar
  • 7,872
  • 19
  • 37
0

I reached out to the creators of RXJS and was told that the creation of custom schedulers are not supported and that that the scheduler area of RXJS is likely to be changed in future and so should not be built upon.

To get around this constraint I refactored my code to be frame independent. I now check to see how long has passed since the last emmition and emmit the correct number of values that should have been triggered in the elapsed time.

colin-bilkins
  • 291
  • 1
  • 3
  • 9