Vapm
  • About
    • Why is it called unblocking?
    • Next update?
    • Credit
    • Info
  • System
    • runEventLoop()
    • runSingleEventLoop()
    • setTimeout()
    • setInterval()
    • fetch()
    • read()
    • time() & timeEnd()
  • Asynchronous
    • getId()
    • await()
  • Promise
    • c()
    • getId()
    • getFiber()
    • isJustGetResult()
    • getTimeOut()
    • getTimeStart()
    • getTimeEnd()
    • setTimeEnd()
    • canDrop()
    • getStatus()
    • getResult()
    • getReturn()
    • getCallback()
    • resolve() & reject()
    • then() & catch() & finally()
    • useCallbacks()
    • all()
    • allSettled()
    • any()
    • race()
    • Some common methods
  • CoroutineGen
    • runBlocking()
    • runNonBlocking()
    • Deferred
    • Deferred Await All
    • repeat() & delay()
    • Channel
      • Example about Channel
    • AwaitGroup
      • Example
    • Mutex
      • Example
    • Goroutine vs CoroutineGen
      • Concurrency
  • Thread
    • How do I create a thread?
    • How do I share data between threads?
    • Advanced Thread
  • Worker
    • Example
  • Stream
    • read()
    • write()
    • append()
    • delete()
    • create()
    • overWrite()
  • FAQ
    • Why System::runEventLoop() and System::runSingleEventLoop() ?
    • Do you want concurrency?
  • PocketMine-PMMP
Powered by GitBook
On this page
  1. CoroutineGen

Goroutine vs CoroutineGen

Goroutine (Golang):

package main

import (
	"fmt"
	"sync"
	"time"
)

func main() {
	wg := &sync.WaitGroup{}

	wg.Add(1)

	start := time.Now()

	go func() {
		defer wg.Done()
		for i := 0; i < 5000000; i++ {
			time.Sleep(time.Millisecond * 1)
		}
	}()

	wg.Wait()
	fmt.Println("Time taken: ", time.Since(start))
}

CoroutineGen (PHP Vapm):

<?php

declare(ticks=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use vennv\vapm\CoroutineGen;
use vennv\vapm\System;

System::time();

function coroutineA()
{
    for ($i = 0; $i < 5000000; $i++) {
        yield CoroutineGen::delay(1);
    }
    System::timeEnd();
}

CoroutineGen::runNonBlocking(coroutineA());
PreviousExampleNextConcurrency

Last updated 9 months ago