UNPKG

@qiniu/miku-delivery-mp-ks

Version:

Kuaishou Mini Program SDK for Miku Delivery

50 lines (49 loc) 2.04 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import Mutex from './mutex'; import { delay } from '../test'; describe('Mutex', () => { it('should work well', () => __awaiter(void 0, void 0, void 0, function* () { const mutex = new Mutex(); const result = []; yield Promise.all([ (() => __awaiter(void 0, void 0, void 0, function* () { result.push('1.0'); const unlock = yield mutex.lock(); result.push('1.1'); yield delay(500); result.push('1.2'); unlock(); }))(), (() => __awaiter(void 0, void 0, void 0, function* () { result.push('2.0'); const unlock = yield mutex.lock(); result.push('2.1'); yield delay(500); result.push('2.2'); unlock(); }))(), (() => __awaiter(void 0, void 0, void 0, function* () { result.push('3.0'); const unlock = yield mutex.lock(); result.push('3.1'); yield delay(500); result.push('3.2'); unlock(); }))() ]); expect(result).toEqual([ '1.0', '2.0', '3.0', '1.1', '1.2', '2.1', '2.2', '3.1', '3.2' ]); })); });