En idioma Go, tiempo Los paquetes proporcionan funcionalidad para determinar y ver el tiempo.
El Dormir() La función en el lenguaje Go se utiliza para detener la última rutina go durante al menos la duración indicada. d . Y una duración del sueño negativa o nula hará que este método regrese instantáneamente. Además, esta función está definida en el paquete de tiempo. Aquí, debe importar el paquete de tiempo para usar estas funciones.
Sintaxis:
func Sleep(d Duration)>
Aquí, d es la duración del tiempo para dormir.
Valor de retorno: Pausa la última rutina durante el tiempo indicado y luego devuelve el resultado de cualquier operación una vez finalizada la suspensión.
Ejemplo 1:
inteligencia artificial y agentes inteligentes
// Golang program to illustrate the usage of> // Sleep() function> > // Including main package> package main> > // Importing fmt and time> import (> >'fmt'> >'time'> )> > // Main function> func main() {> > >// Calling Sleep method> >time>.Sleep(8 *>time>.Second)> > >// Printed after sleep is over> >fmt.Println(>'Sleep Over.....'>)> }> |
>
nueva linea en python
>
Producción:
Sleep Over.....>
Aquí, después de ejecutar el código anterior cuando se llama a la función principal, debido a Dormir método, la operación indicada se detiene durante el tiempo indicado y luego se imprime el resultado.
Ejemplo 2:
numero primo java
// Golang program to illustrate the usage of> // Sleep() function> > // Including main package> package main> > // Importing time and fmt> import (> >'fmt'> >'time'> )> > // Main function> func main() {> > >// Creating channel using> >// make keyword> >mychan1 := make(chan string, 2)> > >// Calling Sleep function of go> >go func() {> >time>.Sleep(2 *>time>.Second)> > >// Displayed after sleep overs> >mychan1 <->'output1'> >}()> > >// Select statement> >select {> > >// Case statement> >case> out := <-mychan1:> >fmt.Println(out)> > >// Calling After method> >case> <->time>.After(3 *>time>.Second):> >fmt.Println(>'timeout....1'>)> >}> > >// Again Creating channel using> >// make keyword> >mychan2 := make(chan string, 2)> > >// Calling Sleep method of go> >go func() {> >time>.Sleep(6 *>time>.Second)> > >// Printed after sleep overs> >mychan2 <->'output2'> >}()> > >// Select statement> >select {> > >// Case statement> >case> out := <-mychan2:> >fmt.Println(out)> > >// Calling After method> >case> <->time>.After(3 *>time>.Second):> >fmt.Println(>'timeout....2'>)> >}> }> |
>
>
bash divide la cadena por delimitador
Producción:
output1 timeout....2>
Aquí, en el código anterior, la salida 1 se imprime como la duración del tiempo de espera (en el método After()) es mayor que el tiempo de suspensión (en el método Sleep()), por lo que la salida se imprime antes de que se muestre el tiempo de espera, pero después de eso, el El siguiente caso tiene una duración de tiempo de espera menor que el tiempo de suspensión, por lo que antes de imprimir la salida se muestra el tiempo de espera, por lo tanto, se imprime el tiempo de espera….2.