www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - need help with vibe.d receive()

reply crimaniak <crimaniak gmail.com> writes:
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.
Jan 10 2018
parent reply =?UTF-8?Q?S=c3=b6nke_Ludwig?= <sludwig+d outerproduct.org> writes:
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).
Jan 16 2018
parent crimaniak <crimaniak gmail.com> writes:
On Tuesday, 16 January 2018 at 08:54:58 UTC, Sönke Ludwig wrote:
...
 The problem is with the `immutable struct StopEvent {}`
Thanks! ...
 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).
No, I can't remove casting here, because some other services can't work with immutable or shared, so I just fix StopEvent type.
Jan 16 2018