github.com/searKing/golang/go@v1.2.74/util/runnable.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package util
     6  
     7  /**
     8   * The <code>Runnable</code> interface should be implemented by any
     9   * class whose instances are intended to be executed by a thread. The
    10   * class must define a method of no arguments called <code>run</code>.
    11   * <p>
    12   * This interface is designed to provide a common protocol for objects that
    13   * wish to execute code while they are active. For example,
    14   * <code>Runnable</code> is implemented by class <code>Thread</code>.
    15   * Being active simply means that a thread has been started and has not
    16   * yet been stopped.
    17   * <p>
    18   * In addition, <code>Runnable</code> provides the means for a class to be
    19   * active while not subclassing <code>Thread</code>. A class that implements
    20   * <code>Runnable</code> can run without subclassing <code>Thread</code>
    21   * by instantiating a <code>Thread</code> instance and passing itself in
    22   * as the target.  In most cases, the <code>Runnable</code> interface should
    23   * be used if you are only planning to override the <code>run()</code>
    24   * method and no other <code>Thread</code> methods.
    25   * This is important because classes should not be subclassed
    26   * unless the programmer intends on modifying or enhancing the fundamental
    27   * behavior of the class.
    28   *
    29   * @author  Arthur van Hoff
    30   * @see     java.lang.Thread
    31   * @see     java.util.concurrent.Callable
    32   * @since   1.0
    33   */
    34  type Runnable interface {
    35  	/**
    36  	 * When an object implementing interface <code>Runnable</code> is used
    37  	 * to create a thread, starting the thread causes the object's
    38  	 * <code>run</code> method to be called in that separately executing
    39  	 * thread.
    40  	 * <p>
    41  	 * The general contract of the method <code>run</code> is that it may
    42  	 * take any action whatsoever.
    43  	 *
    44  	 * @see     java.lang.Thread#run()
    45  	 */
    46  	Run()
    47  }
    48  
    49  type RunnableFunc func()
    50  
    51  func (f RunnableFunc) Run() {
    52  	f()
    53  }