Return value from runTaskAsynchronously?

Discussion in 'Plugin Development' started by rippin, Oct 20, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    rippin

    I've been reading and I believe and I need to use callable and futures but I don't think I can use Callable in runTaskAsynchronously. (I might be wrong). Is there any other async task that I can use? Or is there another way I could get value from a async task.
     
  2. Offline

    RealDope

    Not really sure what you want, but from I think you want BukkitRunnables. Look em up.
     
  3. Offline

    Skyost

    rippin You have :
    - runTaskLater(...) which return a BukkitRunnable.
    - scheduleSyncDelayedTask(...) which return the Task ID.
     
  4. Offline

    rippin

    Well I kind of worded it weird. Here is a simplified example of what I'm trying to do.

    Code:java
    1. public int test(){
    2. final int number = 0;
    3. plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
    4. @Override
    5. public void run() {
    6. number = 5; //cannot assign value here
    7. }
    8.  
    9. });
    10. return number;
    11.  
    12. }
    13.  
     
  5. Offline

    blablubbabc

    You could let your async task run a method when it is done, which takes the number as argument. To run that method sync again just call a sync task inside the async task.

    Example:

    Code:
    public void test(){
      plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
        @Override
        public void run() {
          // get number async:
          final int number = 5;
          plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
            @Override
            public void run() {
              // continue sync:
              doSomething(number);
            }
          });
        }
      });
    }
     
    public void doSomething(int number) {
      System.out.println("Aaaaaand the nuuumber iiiiss..... " + number + " !");
    }
    
     
    rippin likes this.
  6. Offline

    rippin

Thread Status:
Not open for further replies.

Share This Page