Dreckr / Worker

Utility for easy concurrency with isolates
MIT License
35 stars 10 forks source link

Ability to pass in a reference to initialization function #9

Open dkornishev opened 10 years ago

dkornishev commented 10 years ago

Need ability to execute some code when the isolate is first created (to setup a global variable, for example)

Dreckr commented 10 years ago

I can't say I like this idea. My problem with it is that tasks should be self-contained and auto configurable pieces of code that do not rely on the current state of the Isolate and, preferably, keeps its mess to itself.

The user must know for certain that Worker will execute its tasks somewhere (it doesn't matter where) and they will be executed in a deterministic way.

Do you have any compelling use case that could change my mind?

dkornishev commented 10 years ago

I agree with you in principal on worker isolates being task-agnostic.

General use-case is to do some intensive time-intensive initialization and caching the result so that tasks can run faster.

In my case, I need to scan the dart vm for functions with certain annotations.

Problem is exacerbated by the fact that dart doesn't allow functions to be sent across isolates.

See: https://github.com/dkornishev/dherkin/blob/workers/lib/dherkin.dart

_scan function in particular.

I can accomplish same thing with lazy-initialization.

Alternative suggestions would also be eagerly accepted.

Dreckr commented 10 years ago

Danil, thanks for the explanation.

I'm really busy for the next week, so it might take a little while before I release anything.

dkornishev commented 10 years ago

Haha, no worries, I am in same situation most weeks. :) On Jun 19, 2014 11:14 PM, "Diego Rocha" notifications@github.com wrote:

Danil, thanks for the explanation.

I'm really busy for the next week, so it might take a little while before I release anything.

— Reply to this email directly or view it on GitHub https://github.com/Dreckr/Worker/issues/9#issuecomment-46641183.

Dreckr commented 10 years ago

This problem has been softened with events. Now you can listen for isolate spawning and pass an initialization task for each isolate.

I might add some sugar that makes it easy to set an initialization task. I'm still undecided, so I'll leave it open.