scramjetorg / scramjet

Public tracker for Scramjet Cloud Platform, a platform that bring data from many environments together.
https://www.scramjet.org
MIT License
253 stars 20 forks source link

MultiStream.map(...).mux is not a function #101

Closed tiswrt closed 3 years ago

tiswrt commented 3 years ago

MultiStream.map(...).mux is not a function if you try the example from the docs for MultiStreams

const { DataStream, MultiStream } = require('scramjet')

const stream1 = DataStream.fromArray([1,2,3,4,5])
const stream2 = DataStream.fromArray([6,7,8,9,10])

new MultiStream([stream1, stream2])
 .map(stream => stream.filter(n => n % 2))
 .mux();

Throws this error:

TypeError: (intermediate value).map(...).mux is not a function
    at Object.<anonymous> (/Users/abc/Desktop/scramjet/index.js:8:3)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

Node v15.7.0, Scramjet v4.35.11

MichalCz commented 3 years ago

Right - that's a bit of bad API work on our side, but it's been like that for ages sadly. :(

The docs for scramjet.Multistream..map say that it returns a promise... means that either you should do:

new MultiStream([stream1, stream2])
 .smap(stream => stream.filter(n => n % 2))
 .mux();

Or if you want to do something asynchronous:

// somewhere in an async function
await (
  new MultiStream([stream1, stream2])
   .map(stream => stream.filter(n => n % 2))
 )
 .mux();

This trully despicable behaviour should be made up for in the upcoming scramjet 5 (although interface v4 will still be supported via a compatibility layer - so no worries).

Please let me know if this solves your issue.

tiswrt commented 3 years ago

It does, thanks a lot!