Skip to content

Commit

Permalink
五一快乐,隔离一时爽,一直隔离一直爽
Browse files Browse the repository at this point in the history
  • Loading branch information
QuinnDK committed May 4, 2020
1 parent 0155cb2 commit 9c181b8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions scheduler/quequescheduler.go
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@
package scheduler

import (
"crawl/engine"
)

type QueueScheluder struct {
requestChan chan engine.Request
workerChan chan chan engine.Request //二维通道

}

func (s QueueScheluder) Submit(r engine.Request) {
s.requestChan <- r
}

func (s QueueScheluder) configureWorkChan(chan engine.Request) {
panic("implement me")
}

func (s *QueueScheluder) workReady(w chan engine.Request) {

s.workerChan <- w
}

func (s *QueueScheluder) Run() {

var requestQ []engine.Request
var workQ []chan engine.Request
go func() {
for {
var activeRequest engine.Request
var activeWork engine.Request

if len(requestQ) > 0 && len(workQ) > 0 {
activeRequest = requestQ[0]
activeWork = workQ[0]

}

select {

case r := <-s.requestChan:
requestQ = append(requestQ, r)
case w := <-s.workerChan:
workQ = append(workQ, w)
case activeWork <- activeRequest:
workQ = workQ[1:]
requestQ = requestQ[1:]

}

}
}()
}

0 comments on commit 9c181b8

Please sign in to comment.