Events
Events
The idea behind Events is the ability to send data, as parameters, to interested Listeners and call them when an Event happens. The Listeners could be a Closure or a static Class Method.
To note that if the Events\Dispatcher does not instantiate a Listener's Class, then the called method must be static.
Its usage is simple; first, we have to register a Listener, adding:
use Event;
// Add a Listener to the Event 'test'.
Event::listen('test', 'App\Events\Test@handle');
Where the class App\Events\Test is
namespace App\Events;
class Test
{
public static function handle($message)
{
echo $message;
}
}
Then, when the payload is needed, we would fire the Event:
// Prepare the Event payload.
$payload = array(
'Hello, this is an Event!',
);
// Fire the Event 'test'.
Event::fire('test', $payload);
Queued Events
The Queued Events is a method to add a number of Events to a Queue, then firing them together, flushing the Queue. E.g
// Queue the Events
Event::queue('test', array('This is the First Event'));
Event::queue('test', array('This is the Second Event'));
Event::queue('test', array('This is the Third Event'));
// Flush the Queue, firing all defined Events
Event::flush('test');
until() Method
The new method Events\Dispatcher@until is about not firing an Event until the first Listener returns a valid and non-null response.
Its usage is simple:
$response = Event::until('testing', $payload);
if($response !== null) {
// Do something with $response
}
Events的更多相关文章
- ABP(现代ASP.NET样板开发框架)系列之14、ABP领域层——领域事件(Domain events)
点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之14.ABP领域层——领域事件(Domain events) ABP是“ASP.NET Boilerplate P ...
- Node.js:events事件模块
Nodejs的大部分核心API都是基于异步事件驱动设计的,所有可以分发事件的对象都是EventEmitter类的实例. 大家知道,由于nodejs是单线程运行的,所以nodejs需要借助事件轮询,不断 ...
- Events基本概念----Beginning Visual C#
span.kw { color: #007020; font-weight: bold; } code > span.dt { color: #902000; } code > span. ...
- Delphi控件之---通过编码学习TStringGrid(也会涉及到Panel控件,还有对Object Inspector的控件Events的介绍
我是参考了万一的博客里面的关于TStringGrid学习的教程,但是我也结合自己的实际操作和理解,加入了一些个人的补充,至少对我有用! 学用TStringGrid之——ColCount.RowCoun ...
- SSE: server-sent events
当客户端需要定时轮询服务器获取一些消息的时候,可以使用 servser-sent events .NET 服务端: public void ProcessRequest(HttpContext con ...
- nodejs学习之events的使用
实用events做个小例子: var mysql = require("mysql"); var Event = require("events").Event ...
- nodejs学习之events
在node里许多对象都发出事件:一个net.Server对象每次一个连接到来,都发出一个事件,一个fs.readStream对象在文件打开时放出一个事件.所有能放出事件的对象都是event.Event ...
- XE1:使用SSMS创建Extended Events
Extended Events 用于取代SQL trace,是SQL Server 追踪系统运行的神器,其创建过程十分简单. 一,创建Extended Events的Session step1,打开N ...
- Lind.DDD.Events领域事件介绍
回到目录 闲话多说 领域事件大叔感觉是最不好讲的一篇文章,所以拖欠了很久,但最终还是在2015年年前(阴历)把这个知识点讲一下,事件这个东西早在C#1.0时代就有了,那时学起来也是一个费劲,什么是委托 ...
- Google C++单元测试框架GoogleTest---Extending Google Test by Handling Test Events
Google TestExtending Google Test by Handling Test Events Google测试提供了一个事件侦听器API,让您接收有关测试程序进度和测试失败的通知. ...
随机推荐
- 【转】iOS中设置导航栏标题的字体颜色和大小
原文网址:http://www.360doc.com/content/15/0417/11/20919452_463847404.shtml iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参 ...
- APK中java代码反编译
Android APK中的Java代码可以被反编译到什么程度主要看APK的加密程度. 第一种情况:无混淆无加密无加壳.直接利用Dex2jar和JD-GUI可把源码从APK里抠出来,代码逻辑清晰,基本上 ...
- 【转】 COCOS2D-X之使用CURL下载图片的一个简单Demo
#include"curl/curl.h" #pragma comment(lib,"libcurl_imp.lib") bool HelloWorld::i ...
- java并发之CountDownLatch、Semaphore和CyclicBarrier
JAVA并发包中有三个类用于同步一批线程的行为,分别是CountDownLatch.Semaphore和CyclicBarrier. CountDownLatch Java之CountDownLatc ...
- 13、Android的多线程与异步任务
课程目标:学习Android中异步操作的三大方式 重点难点:Handler与线程的关系 Handler消息队列的实现 考核目标: 使用Handler是异步的,它会建立新线程么? no Handle ...
- POJ 2001-Shortest Prefixes(Trie 入门)
题意:给你一组串,求每个串在组中唯一标志的最短前缀 分析:保存树上经过各节点的单词个数,扫描每个串当经过节点单词个数是一(能唯一标志)结束 #include <map> #include ...
- JDBCTemplate.java
package com.pk.xjgs.util; import java.sql.Connection; import java.sql.SQLException; import java.util ...
- 6.2 CUDA streams
stream是什么 nivdia给出的解释是:A sequence of operations that execute in issue-order on the GPU. 可以理解成在GPU上执 ...
- The usage method of reference with bibtex in Latex【latex中参考文献的使用方法】
如何在latex中以Bibtex文件方式引用参考文献? 以IEEEtran模板为例: 1.制作bibtex参考文献库.方法如下: ①建立myreference.bib文件: ②在Google scho ...
- 关于ANSI 和 Unicode
关于ANSI和Unicode 1.ANSI American National Standards Institute(美国国家标准学会),ANSI编码不是一种具体的编码方式,而是一种指定在某些环境下 ...