need help with vibe.d receive()
Sönke Ludwig
sludwig+d at outerproduct.org
Tue Jan 16 08:54:58 UTC 2018
Am 10.01.2018 um 15:39 schrieb crimaniak:
> Hi!
>
> I make multi-task event bus, but there is a problem with the task stops.
> Please see end of file
> https://github.com/crimaniak/d-vision/blob/master/src/vision/eventbus.d
>
> Expected behavior: After sending the StopEvent message in line 244 it is
> must be detected in listeners (line 147), so all listeners must set exit
> flag to 'true' and quit immediately.
> De-facto behavior: StopEvent() message is not detected by the first
> delegate in line 147 (logger task logs this message by the handler in
> line 185), so subscribed tasks never exit and test stops on line 248.
>
> I tried to play with yield() and sleep(), with 'shared' attributes and
> so on, but without result. Can you say please what I am doing wrong here?
>
> 'dub test' can be used to play with tests.
The problem is with the `immutable struct StopEvent {}` declaration and
the use of `shared(Unqual!StopEvent)` - `shared(StopEvent)` is actually
reduced to just `StopEvent`, which internally is expanded to
`immutable(StopEvent)` and `immutable` already implies `shared`.
However, `Unqual!StopEvent` actually removes the implicit `immutable`
from the type, so that `shared(Unqual!StopEvent)` is really just
`shared(StopEvent)` and consequently treated as a different type by
`receive`.
So, removing the `immutable` from the declaration solved the issue for
me, but if possible I'd rather remove the `cast(shared
Unqual!EventType)` from `emit`, and pass `shared`/`immutable` events to
it from the outside (or plain events with no unshared indirections).
More information about the Digitalmars-d-learn
mailing list