Snippets Collections
/**
 *    @module
 *    @author daemon.devin <daemon.devin@gmail.com>
 *
 *    @param {String}   file - The path of the file you want to load.
 *    @param {Function} callback (optional) - Called after script load.
 */
var loader = loader || (Function() {
    return {
    	
    	load: function(file, callback) {

            var script = document.createElement('script');
            script.src = file, script.async = true;
            
  			// If defined, execute the callback after checking 
  			// if the script has been successfully loaded.
            if (callback !== undefined) {
            	
            	// IE calls `script.onreadystatechange()` continuously
            	// as the script loads. Use `script.onreadystatechange()`
            	// to check if the script has finished loading.
	        script.onreadystatechange = function() {
	                
	            // When the script finishes loading, IE sets 
	            // `script.readyState` to either 'loaded' or 'complete'.
	            if (script.readyState === 'loaded' ||
	                script.readyState === 'complete') {
	                    
                  	// Set `onreadystatechange()` to null to prevent 
                  	// it from firing again.
	                script.onreadystatechange = null;
	                    
	                // Execute the callback.
	                callback (file );
	            }
	        };
	            
	        // The following is one of the reasons IE is infereor
            // to all modern browsers.
	        script.onload = function () {
	            callback ( file );
	        };
            }
            
  			// Add the loaded script to the end of the document 
  			// so it won't hinder the rest of the page from loading.
            document.body.appendChild(script);
        } 
    };
}());
async function turnierplan_mit_helfer_teilen() {
  var url_string = window.location.href;
  var url = new URL(url_string);
  var pw = url.searchParams.get("pw");
  var turnier_id = url.searchParams.get("turnier_id");
  
  let turnier = await read_turnier_details(turnier_id, "*", "*");
  ...
}
  
async function read_turnier_details(turnier_id, runde, gruppe){
    var base_url = window.location.origin;
    if( base_url.includes("https://localhost") ){
        base_url = "https://localhost/mytman-repo";
    }
    return jQuery.ajax({
        type: "POST",
        dataType: "json",
        url: base_url + "/app/api/read_turnier_details",
        data: {
            turnier_id: turnier_id,
            runde: runde,
            gruppe: gruppe
        },
        success: function(response){
        }
    });
}
import io

from fastapi import FastAPI
from fastapi.responses import StreamingResponse
from fastapi.staticfiles import StaticFiles


app = FastAPI()

# create a 'static files' directory
# create a '/static' prefix for all files
# serve files from the 'media/' directory under the '/static/' route
#   /Big_Buck_Bunny_1080p.avi becomes '/static/Big_Buck_Bunny_1080p.avi'
# name='static' is used internally by FastAPI
app.mount("/static", StaticFiles(directory="media"), name="static")


@app.get("/")
async def main():
    # open the movie file to stream it
    movie = open("media/Big_Buck_Bunny_1080p.avi", "rb")
    # return a stream response with the movie and a MIME type of 'video/avi'
    return StreamingResponse(movie, media_type="video/avi")
import asyncio

import httpx


async def main():
	async with httpx.AsyncClient() as client:
		resp = await client.get("https://python.org")
        http_text = await resp.text()
		print(http_text)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
import aiohttp
import asyncio
 
 
async def fetch(client):
    async with client.get("https://python.org") as resp:
        assert resp.status == 200
        return await resp.text()
 
 
async def main():
    async with aiohttp.ClientSession() as client:
        html = await fetch(client)
        print(html)
 
 
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
functions.php
/**
 * Esta función agrega los parámetros "async" y "defer" a recursos de Javascript.
 * Solo se debe agregar "async" o "defer" en cualquier parte del nombre del 
 * recurso (atributo "handle" de la función wp_register_script).
 *
 * @param $tag
 * @param $handle
 *
 * @return mixed
 */
function mg_add_async_defer_attributes( $tag, $handle ) {

	// Busco el valor "async"
	if( strpos( $handle, "async" ) ):
		$tag = str_replace(' src', ' async="async" src', $tag);
	endif;

	// Busco el valor "defer"
	if( strpos( $handle, "defer" ) ):
		$tag = str_replace(' src', ' defer="defer" src', $tag);
	endif;

	return $tag;
}
add_filter('script_loader_tag', 'mg_add_async_defer_attributes', 10, 2);



// Ejemplo con "async".
wp_register_script( 'fichero-js-async', get_stylesheet_directory_uri() . '/js/fichero.js', [], false, true );
wp_enqueue_script( 'fichero-js-async' );


// Ejemplo con "defer".
wp_register_script( 'fichero-js-defer', get_stylesheet_directory_uri() . '/js/fichero.js', [], false, true );
wp_enqueue_script( 'fichero-js-defer' );

function promiseWrapper(fn) {
    return (req, res, next) => {
         fn(req, res).catch(next);
    };
}
  const getMovies = async (url) => {
    setError(null);
    try {
      const response = await fetch(url);

      if (!response.ok) {
        throw new Error("Something went wrong!");
      }

      const data = await response.json();
      
      if (data.results.length === 0) {
        throw new Error("Sorry, no movies were found.");
      }
      
      const transformedMovies = data.results.map((movie) => {
        return {
          id: movie.id,
          title: movie.title,
          description: movie.overview,
          rating: movie.vote_average,
          genres: movie.genre_ids,
          poster_path: movie.poster_path,
          backdrop_path: movie.backdrop_path,
          year: movie.release_date
        }
      })
      setTotalPages(data.total_pages);
      setMovies(transformedMovies);
      chooseMovie(transformedMovies);
    } catch (errorThrown) {
      setError(errorThrown.message);
    }
  }
const async = require("async");
async.eachSeries(updates, (up, next) => {
  techEntriesList.push(up.entryId);
  if (up.subJobType && up.userId) {
    up.jobId = jobId;
    updatePeopleWithCallback(jobId, up, jobUpdates, (err, technician) => {
      if (technician) technicianList.push(technician);
      console.log(Date.now());
      next();
      return;
    });
  }
});
star

Thu Oct 19 2023 06:27:29 GMT+0000 (Coordinated Universal Time)

#javascript #module #async #script
star

Thu Jun 15 2023 20:05:47 GMT+0000 (Coordinated Universal Time) https://www.codecademy.com/courses/learn-intermediate-javascript/lessons/js-requests-with-fetch-api/exercises/making-an-async-get-request

#async #await #fetch
star

Tue Jan 10 2023 10:53:52 GMT+0000 (Coordinated Universal Time)

#ajax #async #await
star

Sat Oct 08 2022 22:56:22 GMT+0000 (Coordinated Universal Time)

#python #async #fastapi
star

Mon Sep 19 2022 13:38:35 GMT+0000 (Coordinated Universal Time)

#python #async #requests
star

Mon Jan 31 2022 02:13:17 GMT+0000 (Coordinated Universal Time)

#python #requests #async
star

Fri Oct 22 2021 20:49:54 GMT+0000 (Coordinated Universal Time) https://maugelves.com/como-agregar-async-o-defer-a-los-scripts-en-wordpress/

#php #async
star

Sun Jun 06 2021 15:34:43 GMT+0000 (Coordinated Universal Time)

#nodejs #async #promises #express #javas
star

Mon May 24 2021 17:37:55 GMT+0000 (Coordinated Universal Time)

#react #api #fetch #async #error
star

Wed Jul 08 2020 11:05:33 GMT+0000 (Coordinated Universal Time)

#javascript #async

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension