Snippets Collections
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

Tue Jan 10 2023 10:53:52 GMT+0000 (UTC)

#ajax #async #await
star

Sat Oct 08 2022 22:56:22 GMT+0000 (UTC)

#python #async #fastapi
star

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

#php #async
star

Wed Jul 08 2020 11:05:33 GMT+0000 (UTC)

#javascript #async

Save snippets that work with our extensions

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