Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 12:32
    Andarist commented #7
  • 11:24
    wenfangdu commented #7
  • Oct 04 02:11
    neurosnap labeled #2328
  • Oct 04 02:11
    neurosnap commented #2328
  • Sep 27 07:59
    anjunlee closed #2329
  • Sep 27 07:59
    anjunlee commented #2329
  • Sep 27 07:43
    Andarist commented #2329
  • Sep 27 03:44
    anjunlee edited #2329
  • Sep 27 03:34
    anjunlee edited #2329
  • Sep 27 03:32
    anjunlee opened #2329
  • Sep 26 12:44
    krystiansliwa opened #2328
  • Sep 22 00:41
    neurosnap commented #2327
  • Sep 22 00:40
    neurosnap commented #2327
  • Sep 22 00:39
    neurosnap commented #2327
  • Sep 22 00:39
    neurosnap commented #2327
  • Sep 20 19:29
    gernot-at-etron commented #2327
  • Sep 20 19:27
    neurosnap labeled #2327
  • Sep 20 19:26
    neurosnap commented #2327
  • Sep 20 17:43
    gernot-at-etron edited #2327
  • Sep 20 16:02
    gernot-at-etron opened #2327
Tormen Raßmann
@trassmann

My use case is that I’d like to be able to take just a certain pattern from a channel and ignore the rest

that's standard take behaviour, if nobodys listening for the rest then that is the same as ignoring i guess

Christian Maniewski
@chmanie
@trassmann thank you! But let me see if I got that right.
Currently we’re using an eventChannel to emit certain external events. What I’d like to do is to just take a certain pattern from it. I guess I’d have to do it like this:
const chan = eventChannel(/* do stuff */);
while (true) {
  const event = yield take(channel);
  if (event.type === ’TYPE_THAT_I_WANT’) {
   // Do a certain thing with an event here
  }
}
Christian Maniewski
@chmanie
I thought I might be able to yield take(channel, ‘TYPE_I_WANT’) but that’s just semantics I guess
Tormen Raßmann
@trassmann
image.png
apparently you can in 1.0 with the new multicastchannel
Christian Maniewski
@chmanie
Yeah that’s what I thought!
The API is a little different though and I wonder whether the multicast channel is meant for internalizing these external sources (like the eventChannel does)
I guess I’m just confused of when to use which channel
Tormen Raßmann
@trassmann
i've never worked with eventChannels, but if you're connecting outside sources that seems to be the way to go
i guess it depends on your use case
you could also write a wrapper that accepts a pattern from that particular channel
or funnel the events into another multicast channel
Christian Maniewski
@chmanie
Mhmm that sounds like a good idea. I’ll think about that, thanks!
Christian Maniewski
@chmanie
I wonder why it’s not possible to have a buffer and support patterns in channels
Tormen Raßmann
@trassmann
you could check the different take implementations
it might make the restrictions of the different channel types more apparent
or just wait till @Andarist chimes in :P
Mateusz Burzyński
@Andarist
if you want standard take(channel) behaviour (unicast) but you want only certain items to be received from it then just do an if statement after take
or dont put unwanted actions on the channel in the first place (not sure if feasible though)
A Flores
@unflores
@chmanie eventChannels use buffers no?
Note: messages on an eventChannel are not buffered by default. You have to provide a buffer to the eventChannel factory in order to specify buffering strategy for the channel (e.g. eventChannel(subscriber, buffer)). See the API docs for more info
Christian Maniewski
@chmanie
@Andarist if I do an if-statement, I basically have to re-implement the matching against strings (types) and patterns. It’s not much but it would be great if I could re-use that
Tormen Raßmann
@trassmann
@chmanie i get the point though, usually you have strict control over what goes into your custom channel no? assuming that, generic matching logic would be overkill
Christian Maniewski
@chmanie
Yeah, I guess you’re right, I probably won’t be needing anything besides string comparisons
Christian Maniewski
@chmanie
I have another question: I’m not entirely sure around the workings of the try-finally construct when using a while(true). How do we get in the finally clause there?
Tormen Raßmann
@trassmann
from w3c: The finally statement lets you execute code, after try and catch, regardless of the result.
i dont understand the question, do you mean why it triggers?
Christian Maniewski
@chmanie
Yeah, what kicks us out of the while(true)
Oh, ok probably an error is thrown
Tormen Raßmann
@trassmann
when any code wrapped in a try block throws an exception the catch/finally will trigger
Christian Maniewski
@chmanie
So take(END) actually throws an error?
Tormen Raßmann
@trassmann
END just kills all takers on the standard channel
so take(END) is kinda redundant
Christian Maniewski
@chmanie
But then it’s caught internally by redux-saga somehow, I guess
Tormen Raßmann
@trassmann
its contradictary actually
A Flores
@unflores
right but to get to finally there has to be an exception thrown right?
Tormen Raßmann
@trassmann

right but to get to finally there has to be an exception thrown right?

yea

Christian Maniewski
@chmanie
Note also we're executing the whole while (true) {...} loop inside a try/finally block. When the interval terminates, the countdown function closes the event channel by invoking emitter(END).
Tormen Raßmann
@trassmann

But then it’s caught internally by redux-saga somehow, I guess

probably you are getting an exception because take(END) is not meant to be done, thats what take.maybe is for

Christian Maniewski
@chmanie
Yeah, I think I was just confused that there’s no error but redux-saga seems to catch that specific one for me
A Flores
@unflores
er nm what am I saying.
This message was deleted
try{ console.log('derp') } catch(err){console.log(err)}finally{console.log('yerp')}
gives 'derp' 'yerp'
so no need for an exception to be thrown
Christian Maniewski
@chmanie
wait, where’s your while(true) @unflores
A Flores
@unflores
I was confused about the usage of finally, no idea how they drop out of while(true) maybe a break somehow?