<commit_before>'use strict';

const Kefir = require('kefir');
const common = require('./common.poc');
const Flowable = require('./Flowable');

const flow = new Flowable(common.createIterable());

var sub;
const stream = Kefir.stream(emitter => {
  sub = flow.subscribe({
    next: (x) => emitter.emit(x),
    complete: () => emitter.end()
  });
});

stream
  .bufferWithCount(common.CHUNK_SIZE)
  //.spy()
  .flatMap(x => Kefir.fromPromise(new Promise(pResolve => {
    console.log('ASYNC START', x);
    setTimeout(() => {
      console.log('ASYNC COMPLETE', x);
      pResolve(x);
      sub.request(common.CHUNK_SIZE);
    }, common.DURATION_ASYNC_TASK);
  })))
  .toPromise()
  .then(() => console.log('DONE'));

sub.request(common.CHUNK_SIZE);<commit_msg>improved Kefir version<commit_after>'use strict';

const Kefir = require('kefir');
const common = require('./common.poc');
const Flowable = require('./Flowable');

const flow = new Flowable(common.createIterable());

var sub;

Kefir
  .stream(emitter => {
    sub = flow.subscribe({
      next: (x) => emitter.emit(x),
      complete: () => emitter.end()
    });
    sub.request(common.CHUNK_SIZE);
  })
  .bufferWithCount(common.CHUNK_SIZE)
  //.spy()
  .flatMap(x => Kefir.fromPromise(new Promise(pResolve => {
    console.log('ASYNC START', x);
    setTimeout(() => {
      console.log('ASYNC COMPLETE', x);
      pResolve(x);
      sub.request(common.CHUNK_SIZE);
    }, common.DURATION_ASYNC_TASK);
  })))
  .toPromise()
  .then(() => console.log('DONE'));
{'fraction_non_alphanumeric': 0.19210526315789472, 'fraction_numerical': 0.0, 'mean_word_length': 3.7383177570093458, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4179186', 'n_tokens_mistral': 545, 'n_tokens_neox': 549, 'n_words': 93}