惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
V
Visual Studio Blog
Cyberwarzone
Cyberwarzone
D
Docker
The Hacker News
The Hacker News
C
CERT Recently Published Vulnerability Notes
Vercel News
Vercel News
Project Zero
Project Zero
S
Schneier on Security
aimingoo的专栏
aimingoo的专栏
I
Intezer
腾讯CDC
M
MIT News - Artificial intelligence
Hugging Face - Blog
Hugging Face - Blog
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Vulnerabilities – Threatpost
G
Google Developers Blog
N
Netflix TechBlog - Medium
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
A
Arctic Wolf
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
Recent Announcements
Recent Announcements
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 热门话题
T
Threatpost
Latest news
Latest news
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
The GitHub Blog
The GitHub Blog
T
Tor Project blog
P
Proofpoint News Feed

博客园 - ®Geovin Du Dream Park™

go: Functional Options Pattern go:Timing Functions Pattern python: Timing Functions Pattern go: Steady-State Pattern python: Steady-State Pattern go: Handshaking Pattern python: Handshaking Pattern go: Fail-Fast Pattern python: Fail-Fast Pattern I go: Deadline Pattern python: Deadline Pattern go: Circuit-Breaker Pattern python: Circuit-Breaker Pattern go: Bulkheads Pattern python: Bulkheads Pattern go: Push & Pull Pattern python: Push & Pull Pattern python: Publish/Subscribe Pattern II go: Publish/Subscribe Pattern python: Publish/Subscribe Pattern python: Futures & Promises Pattern go: Worker Pool Pattern go:Pipeline Pattern python: Worker Pool Pattern python: Pipeline Pattern go: Fan-Out Pattern python: Fan-Out Pattern go: Fan-In Pattern python: Fan-In Pattern Fan-In go: Producer Consumer  Pattern python: Producer Consumer Pattern go: Parallelism Pattern python: Parallelism Pattern go: Reactor Pattern python: Reactor Pattern go: Generators Pattern python: speech to text offline python: Generators Pattern go: Coroutines Pattern python:Coroutines Pattern go: Broadcast Pattern python: Broadcast Pattern python: Bounded Parallelism Pattern go: Bounded Parallelism Pattern python: N-Barrier Pattern go: N-Barrier Pattern python: Semaphore Pattern go: Semaphore Pattern python: Read-Write Lock Pattern go: Read-Write Lock Pattern python: Monitor Pattern go: Monitor Pattern python: Mutex Pattern go: Lock/Mutex Pattern Python: Condition Variable Pattern go:Condition Variable Pattern python: Registry Pattern python: Interpreter Pattern go: Interpreter Pattern go: Registry Pattern go: Memento Pattern go: Command Pattern go: State Pattern go:Template Method Pattern go: Strategy Pattern go: Visitor Pattern go: Observer Pattern go: Mediator Pattern go: Iterator Pattern go: Chain of Responsibility Pattern go: Proxy Pattern go:Decorator Pattern go: Facade Pattern go: Flyweight Pattern go: Composite Pattern go: Singleton Pattern go: Prototype Pattern go: Bridge Pattern go: Adapter Pattern go: Builder Pattern 密码进行加盐哈希 using CSharp,Python,Go,Java go: Abstract Factory Pattern go: Model,Interface,DAL ,Factory,BLL using mysql go: Simple Factory Pattern go: Factory Method Pattern go: goLang 在Windows环境搭建Go语言开发环境 CSharp: Parallel Extensions cpp: class python: 蝴蝶跟随鼠标 javascript: 中国历史人物热力分布图using echart javascript: 中国历史人物热力图 python: 初养龙虾微信纯文字自动回复using workBuddy python: object 入门 python: Factory Method Pattern python: Simple Factory Pattern python: Abstract Factory Pattern 区域化 代码 python: Null Object Pattern python: Builder Pattern python: Adapter Pattern
go: Futures & Promises Pattern
®Geovin Du Dream Park™ · 2026-06-23 · via 博客园 - ®Geovin Du Dream Park™

项目结构:

image

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Futures & Promises Pattern 链式契约模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/23 20:47
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : logger.go
*/
package utils

import (
	"log"
	"os"
	"time"
)

type Logger struct {
	inner *log.Logger
}

func NewLogger(name string) *Logger {
	l := &Logger{
		inner: log.New(os.Stdout, "", 0),
	}
	return l
}

func (l *Logger) Info(msg string) {
	now := time.Now().Format("2006-01-02 15:04:05")
	l.inner.Printf("[%s] INFO %s\n", now, msg)
}





/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Futures & Promises Pattern 链式契约模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/23 20:47
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : order_state.go
*/
package core

// 订单状态枚举
type OrderState string

const (
	StateCreated       OrderState = "已创建"
	StatePurchasing    OrderState = "采购中"
	StatePurchased     OrderState = "采购完成"
	StateDesigning     OrderState = "设计中"
	StateDesigned      OrderState = "设计完成"
	StateManufacturing OrderState = "加工中"
	StateManufactured  OrderState = "加工完成"
	StateQualityCheck  OrderState = "质检中"
	StateQualified     OrderState = "质检通过"
	StateStoring       OrderState = "入库中"
	StateCompleted     OrderState = "全部完成"
	StateFailed        OrderState = "执行失败"
)



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Futures & Promises Pattern 链式契约模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/23 20:48
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : base_task.go
*/
package core

// 任务抽象接口 Promise 契约
// ITask 所有工序任务统一接口(对应Python ITask Promise)
type ITask interface {
	Execute(args ...interface{}) (interface{}, error)
	GetName() string
}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Futures & Promises Pattern 链式契约模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/23 20:50
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : purchase_task.go
*/
package tasks

import (
	"godesginpattern/futurespromises/core"
	"godesginpattern/futurespromises/utils"
	"time"
)

// 采购任务
type PurchaseTask struct {
	logger *utils.Logger
}

func NewPurchaseTask() core.ITask {
	return &PurchaseTask{
		logger: utils.NewLogger("PurchaseTask"),
	}
}

func (p *PurchaseTask) Execute(args ...interface{}) (interface{}, error) {
	p.logger.Info("开始采购 1克拉 GIA 裸石...")
	time.Sleep(2 * time.Second)
	res := "1克拉GIA裸石"
	p.logger.Info("采购完成:" + res)
	return res, nil
}

func (p *PurchaseTask) GetName() string {
	return "采购任务"
}





/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Futures & Promises Pattern 链式契约模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/23 20:50
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : design_task.go
*/
package tasks

import (
	"fmt"
	"godesginpattern/futurespromises/core"
	"godesginpattern/futurespromises/utils"
	"time"
)

// 设计任务
type DesignTask struct {
	logger *utils.Logger
}

func NewDesignTask() core.ITask {
	return &DesignTask{
		logger: utils.NewLogger("DesignTask"),
	}
}

func (d *DesignTask) Execute(args ...interface{}) (interface{}, error) {
	stone := args[0].(string)
	d.logger.Info(fmt.Sprintf("根据裸石【%s】开始3D设计...", stone))
	time.Sleep(1 * time.Second)
	res := "钻戒3D设计图纸"
	d.logger.Info("设计完成:" + res)
	return res, nil
}

func (d *DesignTask) GetName() string {
	return "设计任务"
}



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Futures & Promises Pattern 链式契约模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/23 20:51
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : manufacture_task.go
*/
package tasks

import (
	"fmt"
	"godesginpattern/futurespromises/core"
	"godesginpattern/futurespromises/utils"
	"time"
)

// 加工任务
type ManufactureTask struct {
	logger *utils.Logger
}

func NewManufactureTask() core.ITask {
	return &ManufactureTask{
		logger: utils.NewLogger("ManufactureTask"),
	}
}

func (m *ManufactureTask) Execute(args ...interface{}) (interface{}, error) {
	stone := args[0].(string)
	design := args[1].(string)
	m.logger.Info(fmt.Sprintf("加工:%s + %s", stone, design))
	time.Sleep(3 * time.Second)
	res := "1克拉定制钻戒成品"
	m.logger.Info("加工完成:" + res)
	return res, nil
}

func (m *ManufactureTask) GetName() string {
	return "加工任务"
}



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Futures & Promises Pattern 链式契约模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/23 20:52
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : quality_task.go
*/
package tasks

import (
	"fmt"
	"godesginpattern/futurespromises/core"
	"godesginpattern/futurespromises/utils"
	"time"
)

// 质检任务
type QualityCheckTask struct {
	logger *utils.Logger
}

func NewQualityCheckTask() core.ITask {
	return &QualityCheckTask{
		logger: utils.NewLogger("QualityTask"),
	}
}

func (q *QualityCheckTask) Execute(args ...interface{}) (interface{}, error) {
	product := args[0].(string)
	q.logger.Info(fmt.Sprintf("质检:%s", product))
	time.Sleep(1 * time.Second)
	q.logger.Info("质检通过")
	return product, nil
}

func (q *QualityCheckTask) GetName() string {
	return "质检任务"
}



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Futures & Promises Pattern 链式契约模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/23 20:52
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : storage_task.go
*/
package tasks

import (
	"fmt"
	"godesginpattern/futurespromises/core"
	"godesginpattern/futurespromises/utils"
	"time"
)

// 入库任务
type StorageTask struct {
	logger *utils.Logger
}

func NewStorageTask() core.ITask {
	return &StorageTask{
		logger: utils.NewLogger("StorageTask"),
	}
}

func (s *StorageTask) Execute(args ...interface{}) (interface{}, error) {
	product := args[0].(string)
	s.logger.Info(fmt.Sprintf("入库:%s", product))
	time.Sleep(1 * time.Second)
	res := fmt.Sprintf("可销售:%s", product)
	s.logger.Info("入库完成:" + res)
	return res, nil
}

func (s *StorageTask) GetName() string {
	return "入库任务"
}


/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Futures & Promises Pattern 链式契约模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/23 20:53
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : process_service.go
*/
package service

import (
	"fmt"
	"godesginpattern/futurespromises/core"
	"godesginpattern/futurespromises/utils"
)

// 流程调度服务(核心 Future/Promise 链式执行)
type JewelryProcessService struct {
	logger *utils.Logger
	state  core.OrderState
}

func NewJewelryProcessService() *JewelryProcessService {
	svc := &JewelryProcessService{
		logger: utils.NewLogger("ProcessService"),
		state:  core.StateCreated,
	}
	svc.logger.Info(fmt.Sprintf("订单已创建 | 状态:%s", svc.state))
	return svc
}

func (s *JewelryProcessService) updateState(newState core.OrderState) {
	s.state = newState
	s.logger.Info(fmt.Sprintf("状态更新 → %s", newState))
}

// StartFullProcess 链式异步执行所有工序,模拟Future占位符流程
func (s *JewelryProcessService) StartFullProcess(
	purchase, design, manufacture, quality, storage core.ITask,
) (string, error) {
	// 1.采购
	s.updateState(core.StatePurchasing)
	stone, _ := purchase.Execute()
	s.updateState(core.StatePurchased)

	// 2.设计
	s.updateState(core.StateDesigning)
	designDoc, _ := design.Execute(stone)
	s.updateState(core.StateDesigned)

	// 3.加工
	s.updateState(core.StateManufacturing)
	product, _ := manufacture.Execute(stone, designDoc)
	s.updateState(core.StateManufactured)

	// 4.质检
	s.updateState(core.StateQualityCheck)
	qualified, _ := quality.Execute(product)
	s.updateState(core.StateQualified)

	// 5.入库
	s.updateState(core.StateStoring)
	finalRaw, _ := storage.Execute(qualified)
	s.updateState(core.StateCompleted)

	return finalRaw.(string), nil
}

 调用:

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Futures & Promises Pattern 链式契约模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/23 20:54
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : futurespromisesbll.go
*/
package bll

import (
	"fmt"
	"godesginpattern/futurespromises/service"
	"godesginpattern/futurespromises/tasks"
	"time"
)

func demo() {
	// 实例化所有Promise任务
	purchase := tasks.NewPurchaseTask()
	design := tasks.NewDesignTask()
	manufacture := tasks.NewManufactureTask()
	quality := tasks.NewQualityCheckTask()
	storage := tasks.NewStorageTask()

	// 流程调度服务
	process := service.NewJewelryProcessService()

	// 启动全流程链式Future执行
	finalResult, err := process.StartFullProcess(purchase, design, manufacture, quality, storage)
	if err != nil {
		fmt.Println("流程执行失败:", err)
		return
	}

	// 等待5秒,保证最后日志完整输出,避免穿插输入框
	fmt.Println("\n⏳ 等待5秒,收集完整流程日志...")
	time.Sleep(5 * time.Second)

	fmt.Println("\n" + "============================================================")
	fmt.Printf("✅ 订单最终交付:%s\n", finalResult)
	fmt.Println("============================================================")
}

func FuturesPromisesMain() {
	demo()
}

输出:

image

哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)