promises

package
v0.0.0-...-deba56b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2023 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package promises provides helpers for working with promises in k6.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(vu modules.VU) (p *goja.Promise, resolve func(result any), reject func(reason any))

New can be used to create promises that will be dispatched to k6's event loop.

Calling the function will create a goja promise and return its `resolve` and `reject` callbacks, wrapped in such a way that it will block the k6 JavaScript runtime's event loop from exiting before they are called, even if the promise isn't resolved by the time the current script ends executing.

A typical usage would be:

   func myAsynchronousFunc(vu modules.VU) *(goja.Promise) {
	    promise, resolve, reject := promises.New(vu)
	    go func() {
	        v, err := someAsyncFunc()
			   if err != nil {
	            reject(err)
	            return
	        }

	        resolve(v)
	    }()
	    return promise
	  }

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL