These are chat archives for petabridge/akka-bootcamp

15th
May 2017
smalezic
@smalezic
May 15 2017 13:05
What is the best strategy for using actor system in events which are raised on separate threads. For example, how to use actors in file system watcher scenario? I created an actor for watching a folder. When a file is copied into this folder I want to create a child actor to process the file. Speaking of .Net, for every file copied, the FileSystemWatcher raises an event which can't access the main actor Context, so it is not possible to create a new actor from within this event.
How to accomplish this?
mwardm
@mwardm
May 15 2017 16:19
Save an IActorRef to the actor in an instance variable somewhere; when the event's raised, do a storedActorRef.Tell(<some message that identifies the necessary characteristics of the event>); make sure your actor handles that message ?
(You might also be able to close the event handler over the actor Context, but with my limited knowledge and understanding I can imagine there are cases where that might be a bad move (like could the event trigger on a thread other than the one on which the actor logic runs?). But sending a message must be concurrency-safe.)
mwardm
@mwardm
May 15 2017 16:35
( @smalezic )