* use node ace repl
loadModels()
const users = await models.User.all()
console.log(users)
Thank you.
* use node ace repl
Thank you.
* Nodejs use
+ Single-threaded with Event Loop:
when a request is made, it is added to the event loop, which is a queue
of pending requests. Node.js then continues executing the remaining
code, rather than waiting for the request to be completed. When the
request is completed, Node.js retrieves it from the event loop and
returns the result to the client.
+ Event-driven, non-blocking I/O: allows it to handle multiple requests and connections concurrently without blocking the execution of other code.
* There are 3 ways to use asynchronous in nodejs: callback, promises, async/await
1. Callbacks functions
- Callbacks are functions that are passed as arguments to other functions and are executed when the operation completes.
- Callbacks are commonly used to handle asynchronous operations.
* function(err, data): is callback (is the second parameter of readFile() method)
2. Promises
- Promises represent a value that may not be avaiable
* (data) is promises (is return by method readFile())
3. Async/await syntax
- Async/await is a syntax allows to write asynchronous code that looks and behaves like synchronous code
Thank you
1. Install Supervisor
2. To add programs to Supervisor
- way 1: configure it by editing the configuration file located at /etc/supervisor/supervisord.conf.
- way 2: create a new configuration file with a .conf extension in the /etc/supervisor/conf.d/ directory.
* reload supervisor
3. example supervisor.conf for laravel
Thank you
1. Install packages
- Install RabbitMQ Queue driver for Laravel
- Install PHP client for RabbitMQ to work between PHP and rabbitmq
2. Update queue.php config
3. Update .env
4. Create HelloWorldJob
* Call job
5. Show result
- access: http://localhost:15672/#/queues/%2F/default
Thank you
1. Using Synchronous
The program waits for the current task to finish before starting the next task
output
Or
output
2. Using Asynchronous
The program can continue to execute while waiting for a task to complete
You have to install ReactPHP to use asynchronous in PHP
Thank you
1. Using Synchronous
The program waits for the current task to finish before starting the next task
output
2. Using Asynchronous
The program can continue to execute while waiting for a task to complete
output
Thank you