Runnables!

What is Sponge planning to do in the way of Runnables? BukkitRunnables are very useful in Bukkit, so I think Sponge should make something very similar.

Example:

new SpongeRunnable()
{
@Override
public void run()
{
//Do stuff
if(something)
{
cancel();
}
}
}.runTaskTimer(module, 10L, 10L);

What do you think?

1 Like
1 Like

http://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html

No point making your own clone when it’s in the stdlib already.

They mean the helper scheduler functions. They don’t mean their own actual interface.

Ah, sure. That sounds more reasonable, though I think the helper methods should be part of a semi-global context object instead of on the runnable itself.

They are more like abstract classes. The stuff they add are gonna be part of the object. However the method public void run(); must still be implemented for their class to compile / run.

Its only an expansion to the api.

It is how OOP (Object Oriented Programming) works.

I know how OOP works, but I don’t think it’s the right place to implement it here. For one, because since the runnable doesn’t have context currently, it would either need that provided (meaning a context object is required anyway) or the task scheduler would have to be a singleton, which seems to be against what I’ve seen from the rest of the code so far. Second of all, I believe in separating code manipulating data from code doing stuff with data. Look at how Scala’s Futures work, and how every method that would require scheduling another task takes an ExecutionContext that does the hard lifting.