Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

见图片,并发下数据会有问题 #48

Closed
pigfu opened this issue May 6, 2023 · 1 comment
Closed

见图片,并发下数据会有问题 #48

pigfu opened this issue May 6, 2023 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@pigfu
Copy link

pigfu commented May 6, 2023

func (em *Manager) Fire(name string, params M) (err error, e Event) {
	name = goodName(name)

	// NOTICE: must check the '*' global listeners
	if false == em.HasListeners(name) && false == em.HasListeners(Wildcard) {
		// has group listeners. "app.*" "app.db.*"
		// eg: "app.db.run" will trigger listeners on the "app.db.*"
		pos := strings.LastIndexByte(name, '.')
		if pos < 0 || pos == len(name)-1 {
			return // not found listeners.
		}

		groupName := name[:pos+1] + Wildcard // "app.db.*"
		if false == em.HasListeners(groupName) {
			return // not found listeners.
		}
	}

	// call listeners use defined Event
	if e, ok := em.events[name]; ok {
		if params != nil {
			e.SetData(params)
		}

		err = em.FireEvent(e)
		return err, e
	}

	// create a basic event instance
	e = em.newBasicEvent(name, params)
	// call listeners handle event
	err = em.FireEvent(e)
	return
}

这个函数的如下逻辑

if e, ok := em.events[name]; ok {
		if params != nil {
			e.SetData(params)
		}

		err = em.FireEvent(e)
		return err, e
	}

在并发下会有数据互相覆盖的情况

@inhere inhere added the bug Something isn't working label May 6, 2023
@inhere inhere modified the milestones: v1.10, v1.1.0 Jun 4, 2023
@inhere
Copy link
Member

inhere commented Jun 8, 2023

已经调整逻辑,更新到 v1.1.0 试试呢

@inhere inhere closed this as completed Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants